> For the complete documentation index, see [llms.txt](https://user.netmera.com/netmera-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://user.netmera.com/netmera-developer-guide/api-documentation/recipes/sending-sms.md). Agents can also search and read this documentation through its [MCP server](https://user.netmera.com/netmera-developer-guide/~gitbook/mcp).

# Sending an SMS to a User

Add phone numbers to Netmera and send an SMS by notification key or by phone number.

This recipe shows how to add phone numbers to Netmera and send an SMS to a user, either with an SMS created in the Netmera panel or by phone number with the IYS message and recipient types.

## When to Use

This recipe fits one-to-one text messages that your system sends after an event, such as an order update or a verification message.

There are two ways to send the SMS. Choose the one that fits how your system knows the recipient and where the text is written:

|                                 | With a notification key (Step 2)  | By phone number (Step 3) |
| ------------------------------- | --------------------------------- | ------------------------ |
| Where the text is written       | In the panel, once                | In every request         |
| How the recipient is identified | External ID of the user (`extId`) | Phone number (`msisdn`)  |
| Service                         | `sendNotification`                | `sendEmailAndSms`        |

## Prerequisites

* REST API key of the application
* The `notificationKey` of an SMS notification created in the Netmera panel
* The external ID (`extId`) or the phone number of the recipient. Phone numbers must include the country code, for example `+90xxxxxxxxxx`.

## Step 1: Add the Phone Number to Netmera

If the recipient is not a Netmera user yet, upload the number with `addMsisdn`.

```bash
curl https://restapi.netmera.com/rest/3.0/addMsisdn \
  --request POST \
  --header 'Content-Type: application/json' \
  --header 'X-netmera-api-key: <API_KEY>' \
  --data '{
  "msisdnList": ["+90xxxxxxxxxx"]
}'
```

{% hint style="warning" %}
The country code is mandatory. Send numbers in the `+90xxxxxxxxxx` format.
{% endhint %}

If a user with the same MSISDN already exists, a new user is not created. A user created with `addMsisdn` has no installation ID. If the SDK later creates a user with the same MSISDN, the user created with `addMsisdn` is deleted, because the information from the SDK is considered primary.

**Expected result:** The number is available in Netmera as a recipient.

## Step 2: Send the SMS with a Notification Key

Call `sendNotification` with the `notificationKey` of the SMS created in the panel and the external ID of the user in `target.extId`.

```bash
curl https://restapi.netmera.com/rest/3.0/sendNotification \
  --request POST \
  --header 'Content-Type: application/json' \
  --header 'X-netmera-api-key: <API_KEY>' \
  --data '{
  "notificationKey": "3964",
  "target": {
    "extId": "user_1001"
  },
  "message": {
    "params": {}
  }
}'
```

**Expected result:** The request is sent with the key of the SMS created in the panel and the external ID of the recipient.

## Step 3: Send an SMS by Phone Number

To address the recipient by phone number, send the request to `sendEmailAndSms` with `SMS` in `platforms` and the number in `target.msisdn`.

```bash
curl https://restapi.netmera.com/rest/3.0/sendEmailAndSms \
  --request POST \
  --header 'Content-Type: application/json' \
  --header 'X-netmera-api-key: <API_KEY>' \
  --data '{
  "target": {
    "msisdn": "+90xxxxxxxxxx"
  },
  "platforms": ["SMS"],
  "title": "Order Update",
  "message": "Hello, your order is on its way.",
  "smsHeader": "NETMERA",
  "smsIysMessageType": "N",
  "smsIysRecipientType": "B"
}'
```

`smsIysMessageType` is `N` for a notification and `C` for a campaign. `smsIysRecipientType` is `B` for a personal recipient and `T` for a trader.

What these fields mean:

* `smsHeader` is the sender name that the recipient sees, such as your brand name. Use a header that is defined for your account with your SMS provider.
* In Turkey, consent for commercial messages is recorded in IYS (İleti Yönetim Sistemi), the national consent registry. The IYS fields describe the message for this check:

| Field                 | Value | Meaning                                                                                       |
| --------------------- | ----- | --------------------------------------------------------------------------------------------- |
| `smsIysMessageType`   | `N`   | Notification: an informational message, such as an order update or a verification code        |
| `smsIysMessageType`   | `C`   | Campaign: a commercial message, such as a promotion, which needs the consent of the recipient |
| `smsIysRecipientType` | `B`   | The recipient is an individual                                                                |
| `smsIysRecipientType` | `T`   | The recipient is a trader, such as a business                                                 |

**Expected result:** The request is sent with the phone number, the SMS header, and the IYS types.

## Step 4: Track the Results

For an SMS sent with a notification key as in Step 2, call `getPushResult` with the same key to read the result of each SMS. Each entry has `"platform": "SMS"` and a `status` of `SUCCESS` or `FAILED`. A failed entry also carries an `errorCode` and an `errorMsg`.

```bash
curl 'https://restapi.netmera.com/rest/3.0/getPushResult?notificationKey=3964&max=10' \
  --header 'X-netmera-api-key: <API_KEY>'
```

Add `extId` to the query to see the results of one user only. Without `start` and `end`, the results of the last 2 weeks are returned.

**Expected result:** One entry per SMS, with its status.

## Troubleshooting

| Symptom                                              | Likely cause                                                                                                 | Solution                                                                                                                                          |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| The number is not added, or the SMS does not arrive  | The number was sent without the country code                                                                 | Send the number in the `+90xxxxxxxxxx` format.                                                                                                    |
| The SMS sent with a notification key does not arrive | The external ID does not belong to a user with a phone number, or the API key belongs to another application | Check that the user of the `extId` has a phone number in Netmera. Check that the API key belongs to the application in which the SMS was created. |
| A campaign SMS does not reach some users             | The message is sent with `smsIysMessageType` `C` and those users have no recorded consent                    | Send commercial messages only to users with consent. Use `N` only for informational messages.                                                     |
| `getPushResult` returns an entry with `FAILED`       | The SMS could not be delivered                                                                               | Read the `errorCode` and `errorMsg` of the entry to find the reason.                                                                              |

## Verification Checklist

* Phone numbers include the country code
* The `notificationKey` belongs to an SMS created in the Netmera panel
* `target` holds the external ID in `sendNotification` and the phone number in `sendEmailAndSms`
* `smsIysMessageType` and `smsIysRecipientType` are set to a documented value
* `smsIysMessageType` matches the content: `C` for commercial, `N` for informational
* Results of sends with a notification key are read with `getPushResult`

## Related Pages

For the SMS request formats, see the SMS section of the [Notifications](https://user.netmera.com/netmera-developer-guide/api-documentation/rest-api/notifications.md) page. For the IYS consent setup of your SMS provider, see the SMS Providers section of the integrations. To manage SMS permissions and number updates, see the [User & Device Management](https://user.netmera.com/netmera-developer-guide/api-documentation/rest-api/user-and-device-management.md) page and the recipe [Managing Channel Permissions and Category Preferences](https://user.netmera.com/netmera-developer-guide/api-documentation/recipes/managing-channel-and-category-preferences.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://user.netmera.com/netmera-developer-guide/api-documentation/recipes/sending-sms.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
