Providers / Netgsm

Test Netgsm SMS without sending real messages

otpmock emulates the Netgsm REST v2 SMS and OTP API. In your test environment, the official @netgsm/sms SDK talks to otpmock instead of Netgsm; your end-to-end tests read each code over HTTP.

Updated October 8, 2026Tested with the official @netgsm/sms SDK
Short answer

Set OTPMOCK_URL=https://api.otpmock.com in your test environment, point the Netgsm client at it, and use your otpmock API key as the Netgsm credential. Your application code doesn't change, and production keeps sending real SMS through Netgsm.

Setup

The SDK has no base URL option, but its baseURL property can be set after construction (it's private only in the TypeScript types).

sms.ts
import { Netgsm } from "@netgsm/sms";

export const netgsm = new Netgsm({
  username: process.env.NETGSM_USERNAME, // otpmock API key in tests
  password: process.env.NETGSM_PASSWORD,
});
if (process.env.OTPMOCK_URL) (netgsm as any).baseURL = process.env.OTPMOCK_URL;

Credentials. In the test environment, set the Netgsm username (or password) to your otpmock API key. Basic auth is read from either field.

What otpmock emulates

EndpointWhat it does
POST /sms/rest/v2/sendSend SMS (code "00" on success)
POST /sms/rest/v2/otpSend an OTP SMS

Responses and errors follow Netgsm's own format, so the SDK parses them as usual. Authentication failures and an exhausted monthly allowance also come back in Netgsm's error shape.

Phone numbers

Netgsm uses Turkish local numbers (5321234567). otpmock stores them as +905321234567; query that form in tests.

Read the code in your tests

signup.spec.ts
const phone = otp.randomPhone();
const since = Date.now() - 5_000;
await page.getByRole("button", { name: "Send code" }).click(); // your app calls Netgsm
const { code } = await otp.waitForCode(phone, { since });

The otp helper is a single file: get it from the docs. Full walkthroughs: Playwright, Cypress.

Good to know

FAQ

Does otpmock send real SMS through Netgsm?

No. In the test environment your app's Netgsm requests go to otpmock, which stores the message for 10 minutes and never contacts Netgsm or any carrier. Production keeps using Netgsm because otpmock is only enabled when OTPMOCK_URL is set.

Is the official @netgsm/sms SDK supported?

Yes. otpmock's Netgsm endpoints are tested end to end with the official @netgsm/sms package for Node.js. Other languages work too if their Netgsm client lets you change the API host.

Which Netgsm APIs does otpmock support?

POST /sms/rest/v2/send (Send SMS (code "00" on success)); POST /sms/rest/v2/otp (Send an OTP SMS).

Test Netgsm flows today

The free plan includes 100 messages a month. Using an AI coding assistant? Point it at otpmock.com/llms-full.txt.

Get a free API key

Other providers