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 HTTPS.

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).

Language
sms.tsNode.js · @netgsm/sms
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;

Each language is tested in CI against otpmock with the provider's official SDK, or its plain HTTP API where no SDK can be pointed at another host.

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.

Try it with cURL

Before wiring your app, check the emulation by hand. Put your own key in OTPMOCK_API_KEY; the number is made up. Keep the message text ASCII when you run this from a Windows terminal, which can garble accented letters on the command line.

Send a test SMS
curl https://api.otpmock.com/sms/rest/v2/send \
  -u "$OTPMOCK_API_KEY:x" \
  -H "content-type: application/json" \
  -d '{"msgheader":"BASLIGIM","messages":[{"msg":"Dogrulama kodunuz: 482913","no":"5321234567"}],"encoding":"TR"}'
Response
{"code":"00","jobid":"64271089041352956440282421","description":"queued"}

The response has Netgsm's own shape. Now read the code your test would read:

Read the code
curl https://api.otpmock.com/v1/inbox/%2B905321234567/code \
  -H "Authorization: Bearer $OTPMOCK_API_KEY"

{"code":"482913","messageSid":"SM…","receivedAt":1795257752284}

Phone numbers

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

How to tell your app uses Netgsm

Look for any of these in your codebase to confirm where the SMS is sent, and therefore where the otpmock option has to be set:

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 300 messages a month. Using an AI coding assistant? Point it at otpmock.com/llms-full.txt.

Get a free API key

Related guides

Other providers