Msg91 Help Doc
API

API

APIs


image


2. Select the SMS option from the dashboard 



3. Under "SMS", click "Support" in the sidebar & Select the API documentation option on the dropdown.


image



4. API documentation will get opened.

image


5. You can fill in the parameters, such as template ID (MSG91 template ID), mobile number (including country code), and variables, to get the final API. In the header option, enter the Authkey, and then press "Try" to send the SMS. On the right side of the panel, by clicking on the "more" option in Sample Codes, you can get the API codes in various languages. 

image



NOTE:

For SMS API integration, variable values keep on changing, you may have 1, 2, 3 variables: or so. Pass the variables in the API depending on the variables you have in your flow and write the variable in the exact format as you did while creating the flow (this is case-sensitive as well). 


1. The mobile variable will always be dynamic, and you have to insert it into the API, which is the mobile number of the user to whom you want to send SMS. 


2. To shorten the URL in your content, pass the value as 1. 


3. The message variable can be static or dynamic, as per your implementation.


4. The authentication key should always be static.

5. In case you want to send the promotional message using the numeric sender ID then please add the parameter route=1 in the payload.

NOTE: If sent without a country code, submission and deduction depend on the detected country based on the starting number: For, 91xxxxxxxxxx, etc

Frequently Asked Questions

Can I send SMS to international numbers using MSG91's API?

You may send SMS to international numbers using MSG91's API. Just make sure to use the full international phone number format, including the country code. Additionally, set the country parameter to 0 in your API request to indicate it's an international message. Let me know if you need more information!

Is there any way to schedule SMS for a specific time?

SMS can be scheduled for a specific time. You can set a future date and time for sending the message by using the send_at parameter in the API request. This allows you to specify when the message should be sent.

Is there any way to automate SMS sending based on triggers or events?

SMS sending can be automated based on triggers or events using MSG91's API. You can integrate the API with your system to send SMS automatically when certain conditions are met, such as when a user registers, places an order, or performs any action that your system tracks.

Can I customize the sender ID when sending SMS using the API?

You can customize the sender ID when sending SMS using the MSG91 API. However, the ability to use a custom sender ID depends on the country you're sending messages to.

To Do SMS API Integration
APItextsms
Jul 14, 2025

An authentication key (Authkey), also known as an API key or access token, is a unique identifier or code that is used to authenticate and authorise requests made to the API. When making API requests, the authentication key is usually included in the request headers or as a query parameter.


It's important to handle authentication keys securely, as they can grant access to sensitive data or functionality.


1. Log in to the MSG91 panel. Select the Authkey option from the top row. You can also select it from the username dropdown or from the bottom left if you are inside any service dashboard.


Kb168543132051926616


2. Enter the registered mobile number and verify with the OTP you will receive on the registered number.


16591634146321659163

3. Click on the Create New option to create an authkey.


Kb168542764557881916


 4. The tab as shown below will get opened.

  • Name the Authkey as per your preference. Please make sure there is no special character in this section.

  • Select its use case in the "Where are you integrating" field or give a new one. 

  • Select the Rule to be applied to that authkey from the Rules dropdown. For example, if permission for only selected services is given in the rule, then the authkey can only be used for those services. You can also create a new rule from the Rules section in the Settings of your account.

  • The IP security is on by default. You can turn it off if required by editing the authkey settings. Whitelist your IPs in the Whitelist IPs field. The IPs whitelisted for the company will be visible under the Company's whitelisted IPs section at the bottom.

Once done, click on the Create button.

Kb168542940643111316

5. A new authentication key will be created and there will be an option to copy it. The IPs you whitelist in the Company's whitelisted IPs then they will be whitelisted for all the authkeys created in your MSG91 account. The Recent IPs will show you the IPs from which we have recently received the submissions from your account. You can whitelist them by the + icon given beside them.

Toggle the “Authkey status” option to disable your Authkey. You can enable the same by toggling again.

Kb168543015235840116


6. You can edit the authkey settings by the pencil icon under the Actions tab.


Kb168542987796341716



Where can I find my authentication key?
my authkeyauthkey of my accountget authkeyfind authkeyauthkey
Nov 11, 2024

API SECURITY


It is an option that allows you to send your messages only through whitelisted IPs via API.


If API security is enabled and you try to send the SMS via any other IP then those requests will be rejected with

error code 418.

 


Let us begin with how you can enable the API Security in your account -


1. Log in to the MSG91 panel and select the Authkey option from the username dropdown. You can also access this dropdown from the bottom left if you are inside any service dashboard.


Kb168543132051926616


2. Enter the registered mobile number and verify with the OTP you will receive on the registered number.


16591634146321659163

3. Now, select the arrow under the Actions tab of the authkey you wish to enable the IP security in. You can enable/disable the IP security from the toggle. Enter the IPs that you wish to whitelist for that particular authkey in the Whitelisted IPs section. The IPs that you have whitelisted for the company will be visible under the Company's whitelisted IPs section at the bottom.


Kb168543257487577416

4. The IPs you whitelist in the Company's whitelisted IPs then they will be whitelisted for all the authkeys created in your MSG91 account. The Recent IPs will show you the IPs from which we have recently received the submissions from your account. You can whitelist them by the + icon given beside them.

Kb168543309042496716


NOTE:-

-> We support IPV6 & IPV4 addresses both. Eg: 2001:db8:3333:4444:5555:6666:7777:8888 (IPV6), 192.0. 2.146 (IPV4)

-> We strongly recommend you to keep it enabled as this provides an extra layer of security to your account.

-> If still you do not wish to have this security feature, you can disable it from the toggle in the authkey.

By doing so, the API will be called by any IP address that is not whitelisted, and MSG91 cannot be held liable for any spamming/fraudulent activities using the API.

How to check from which IP the API requests are failing -

1.  Goto the SMS section from your MSG91 Dashboard.

Kb167481319908520316

2. Select the Failed Logs section from the sidebar. The list of IPs by which the APIs got failed & you received the 418 error code is also available on the MSG91 Dashboard that you can copy & whitelist under Authkey section. 

Kb167481310296493916

Kb167481285776021716


3. Now, if you have enabled the Additional Security option. Enter at least one IP here. And press Yes on the popup window.


4. To whitelist more IPs, enter the IP address & click on Whitelist button.


Screenshot 2022-10-0


Kb167481319908520316


2. Select the Failed Logs section from the sidebar. The list of IPs by which the APIs got failed & you received the 418 error code is also available on the MSG91 Dashboard that you can copy & whitelist under Authkey section. 


Kb167481310296493916


2. We always send alerts on your registered mail ID as well as mobile number, when the API gets failed with 418 error i.e. API security is enabled and you try to call the API via any other IP then, those requests will be rejected.


Note:-


-> We also send alerts on the registered email ID when any changes been made in API security option of your MSG91 account that is new IP is Added, any IP is Deleted, Additional Security is Enabled, and Additional Security is Disabled.











What do you mean by API Security?
IP whitelist418error code 418API SecurityIP security
Nov 11, 2024

ERROR CODES

Error codes are displayed if there's an issue in the message sent by you. Click on the respective code to find out the reason for failed SMS and also to know what that particular code means.

You can also find the reasons for all the error codes for API below:



101

Missing mobile number

102

Missing message

104

Missing username

105

Missing password

201

Invalid username or password. 201 also appears in case the XML code triggered is incorrect.

202

Invalid mobile number

203

Invalid sender ID or DLT Entity Id Missing

207

Invalid authentication key

208

IP is blacklisted

209

Default route not found

210

The route could not be determined. Please contact support

211

DLT Template Id Missing

301

The user does not have sufficient balance to send SMS

302

Expired user account

303

Banned user account

306

This route is currently unavailable

307

The schedule time is incorrect

308

Campaign name cannot be more than 32 characters

309

The selected group(s) does not belong to you

310

SMS is too long. The system paused this request automatically

311

When the same SMS content is sent to the same number within 10 seconds. This is a security feature used to avoid multiple deliveries. The first SMS will be delivered and the second will be rejected. The balance will also be deducted only once.

400

Flow ID Missing or Invalid Flow

401

Flow Not Yet Approved

402

The message has some hard block keywords.

403

Flow is disabled

418

IP not whitelisted

421

Service Terminated (Please reach out to your account manager or write to

[email protected]

)

506

Internal error, please contact your account manager

601

Internal error, please contact your account manager

602

If your current route is disabled, kindly select another route

603

This sender ID is blacklisted, please use a different sender ID

604

Please enter at least one correct number to send an SMS

606

The scheduled date cannot be more than three weeks

607

Please enter the campaign name

608

Scheduled SMS cannot be less than the current end time

What are the reason for error codes received under the API failed?
APIfailederrorerror codesapi
Nov 11, 2024