Quickstart

By the end of this page you will have sent a verification code and checked it. Nothing reaches WhatsApp and nothing is charged, so you can run it as many times as you like.

1. Get a test key

In the dashboard, go to Settings → Console → API keys and create a key.

  • Set the environment to test. The key will start with msg_test_.
  • Give it the otp:send scope.

Copy the secret when it is shown. It is shown once, and a lost secret is rotated rather than recovered. The other fields on the key — limits, expiry, sender — are covered in Set up your API access.

Shell
export MSGEASY_API_KEY=msg_test_...

2. Install the SDK

npm install msgeasy   # Node 18 or newer

3. Send a code

import { MsgEasy } from "msgeasy";
 
const msg = new MsgEasy(process.env.MSGEASY_API_KEY);
 
const verification = await msg.verify.start({ phone: "+919812345678" });

A test key hands you the code back, so you can finish the flow without a real phone and without a template Meta has approved.

4. Check it

const result = await msg.verify.check({
  verificationId: verification.verificationId,
  code: verification.code,
});
 
console.log(result);   // { status: "approved" }

That is a complete verification.

What a wrong code looks like

Not an error. The request was fine; the code was not.

await msg.verify.check({ verificationId, code: "000000" });
// { status: "invalid", remainingAttempts: 4 }

Only approved means the user is verified. The other statuses are listed in Verify a phone number.

What a real error looks like

A refusal raises an error you can catch.

import { MsgEasyError } from "msgeasy";
 
try {
  await msg.verify.start({ phone: "+919812345678" });
} catch (error) {
  if (error instanceof MsgEasyError) {
    console.log(error.code, error.message, error.requestId);
  }
}

By the time an exception reaches you the SDK has already retried anything worth retrying, so there is no retry loop for you to write.

Next