API menu

SMS Documentation

Some countries might require additional information before being able to send SMS messages

Introduction

With the SMS API, anyone can build reliable SMS messaging services using our infrastructure. It is available as a free demo version too. Send some test SMS messages and experiment with the API before taking it into production. In your Developer Portal account you can apply to take the SMS API into production. Bulk SMS is now supported.

API specification

Test the API on SwaggerHub

Base URL

https://api-prd.kpn.com/communication/kpn/sms

Conceptual model

KPN SMS Conceptual model

Definitions

SMS

An abbreviation of Short Message Service. It's a service on mobile phones to send and receive short messages.

API workflow

KPN SMS API workflow

Features and constraints

Features

  • Send a text message to another mobile phone number.
  • Bulk messaging is now supported: multiple message can be sent to a single recipient, as well as a single message to multiple recipients. This combined features: multiple messages to multiple recipients.

Constraints

  • No images can be sent with SMS.
  • Messages longer than 160 characters will be sent as multiple SMS messages. Maximum message length is 1000 characters.
  • With this API, messages can be sent globally to mobile phones. Also 097 range is allowed.
  • With bulk messaging, the maximum number of messages multiplied by number of recipients in a single API call is 200.
  • In sandbox mode, message length is capped to 160 chars. This limitation is of course lifted in the production version.

060xxxxxxx, 067xxxxxxx and 069xxxxxxx are not valid mobile numbers.

Getting started

Make sure you've read What's in it for you for more info on how to register and start testing APIs.

Authentication

The API follows the KPN Store API Authentication Standard to secure the API. It includes the use of OAuth 2.0 client_id and client_secret to receive an access token.

Go to the Authentication tab on top of this page to find out how to:

  • Authenticate to an API using cURL.
  • Authenticate to an API on Swaggerhub.
  • Import Open API Specifications (OAS), also called Swagger files into Postman.

How to...

Send a single SMS

Send an SMS by calling the send endpoint of the SMS API in Swaggerhub or Postman.

post: {BASE_URL}/send

Create your payload for the request using below snippet:

Request example
{ "sender": "KPN API", "expirein": "5", "messages": [ { "mobile_number": "06xxxxxxxx or +316xxxxxxxx", "content": "Hi from KPN!" } ] }

The payload uses following parameters:

Parameter Description
sender A text that should resemble the sender's origin. This string can have a maximum length of 11 characters.
mobile_number The mobile phone number of the addressee. Use the relevant country code at the start. For example, +31 or +44.
content Put your message here. Long messages will be split into multiple SMS.
expirein (Optional) The expirein field sets a time limit, in seconds, for how long the message can be delivered before it expires and is no longer sent.

SwaggerHub:

  1. Select POST /send.
  2. Click Try it out.
  3. Edit the body parameter by providing the payload snippet above. In the payload change the content, mobile_number and sender to your own good. Make sure the content-type is set to application/json.
  4. Click Execute.
  5. Check the response code and message.

Postman:

  1. Select (POST) /send.
  2. In the Body section, set the type to raw and insert the payload snippet above. In the payload change the content, mobile_number and sender to your own good. Make sure the content-type is set to application/json.
  3. Click Send.
  4. Check the response code and message.

Result example:

Response example
{ "document_id": "b4e905d4-774c-4c83-8360-01427e17a33a", "status": "OK" }

Sending bulk SMS's

Sending bulk SMS's uses the same endpoint as a single SMS: the POST /send endpoint of the SMS API in Swaggerhub or Postman. Bulk SMS's are multidimensional, which means that you can:

  • send a single SMS to multiple recipients,
  • send multiple SMS's to a single recipient,
  • a combination of these two options; send multiple SMS's to multiple recipients.

Example of a payload for the request with a single SMS being send to multiple recipients:

Request example
{ "sender": "KPN API", "messages": [ { "mobile_number": "06xxxxxxxx,+316yyyyyyyy,06zzzzzzzz", "content": "Hi from KPN!" } ] }

Example of a payload for the request with a multiple SMS's being send to multiple recipients:

Request example
{ "sender": "KPN API", "messages": [ { "mobile_number": "06xxxxxxxx", "content": "Hi from KPN!" }, { "mobile_number": "+316xxxxxxxx", "content": "Hello there." }, { "mobile_number": "06xxxxxxxx,06yyyyyyyy,+316zzzzzzzz", "content": "Till we meet again." } ] }

Please keep in mind that the maximum message length is 1000 characters. Maximum messages times recipients in one API call is capped to 200 messages.

You will be charged for every SMS you send to a recipient. In the example above where one of the messages is sent to 3 recipients, will be charged as 1 + 1 + 3*1 = 5 SMS's.

This will also work in your sandbox. Feel free to test this, but be aware that you have a limited quota of 25 messages for testing purposes.

The payload uses following parameters:

Parameter Description
sender A text that should resemble the sender's origin. This string can have a maximum length of 11 characters.
mobile_number The mobile phone number(s) of the addressee(s). Use the country code +31 at the start.
content Put your message here. Long messages will be split into multiple SMS.

SwaggerHub:

  1. Select POST /send.
  2. Click Try it out.
  3. Edit the body parameter by providing the payload snippet above. In the payload change the content, mobile_number and sender to your own good. Make sure the content-type is set to application/json.
  4. Click Execute.
  5. Check the response code and message.

Postman:

  1. Select (POST) /send.
  2. In the Body section, set the type to raw and insert the payload snippet above. In the payload change the content, mobile_number and sender to your own good. Make sure the content-type is set to application/json.
  3. Click Send.
  4. Check the response code and message.

Result example:

Response example
{ "document_id": "b4e905d4-774c-4c83-8360-01427e17a33a", "status": "OK" }

Receive notification

For each SMS sent, you can receive a notification. For this you'll need a webhook configured to receive these notifications. By sending the URL of this webhook along with the request, the notification will be delivered on this URL, where you can process this. This applies for single SMS and for bulk SMS. With bulk SMS you can set this up to:

  • receive all notifications in the bulk request on a single URL,
  • receive a notification for one or more recipients on a specific URL,
  • receive a notification for one or more messages on a specific URL,
  • or make a combination of above options; receive notifications on a specific URL for one or more messages, one or more recipients and still use a general URL for the remainder of the messages.

Receiving notifications is free of charge.

Here are a couple of examples of a payload for the request with SMS's being send with the setup of a webhook.

One webhook for one or all SMS
{ "sender": "KPN", "webhook_url": "https://hostname/path", "messages": [{ "content": "Hi from KPN!", "mobile_number": "+316xxxxxxxx" }], }
Webhooks for each SMS
{ "sender": "KPN", "messages": [{ "content": "Hi from KPN!", "mobile_number": "+316xxxxxxxx", "webhook_url": "https://hostname1/path1" },{ "content": "Hi from KPN!", "mobile_number": "+316xxxxxxxx", "webhook_url": "https://hostname2/path2" }], }
A mix – one SMS with a dedicated webhook and others with a general webhook.
{ "sender": "KPN", "webhook_url": "https://hostname/path", "messages": [{ "content": "Hi from KPN!", "mobile_number": "+316xxxxxxxx" },{ "content": "Another Hi from KPN!", "mobile_number": "+316xxxxxxxx", "webhook_url": "https://hostname2/path2" },{ "content": "Yet another hi from KPN!", "mobile_number": "+316xxxxxxxx" }], }

Dedicated webhook(s) have a priority over the general one.

On the webhook you are going to receive a json message. The structure is as follows:

Notification received example
{ "Fields": { "Status": { "StatusDateTime": "2021-12-02T13:25:34Z", "StatusValue": "1", "StatusCode": "Delivered" }, "Sender": "KPN", "WebhookURL": "https://hostname/path", "Message": "Hi There", "RecipientPhonenumber": "+316xxxxxxxx", "CustomerId": "email@domain.com" }, "DLRID": "9F7742AD353FSGS2345SDCDSV45C02", "Service": "Sms", "MessageType": "SmsDeliveryReport", "MessageID": "4C0FWFWE86EE492ABCD34534122hJKHKHFDW" }
Error Notification received example:
{ "Fields": { "Status": { "StatusDateTime": "2021-12-02T13:25:34Z", "StatusValue": "4", "StatusCode": "Failed", "ErrorValue": "2", }, "Sender": "KPN", "WebhookURL": "https://hostname/path", "Message": "Hi There", "RecipientPhonenumber": "+316xxxxxxxx", "CustomerId": "email@domain.com" }, "DLRID": "9F7742AD353FSGS2345SDCDSV45C02", "Service": "Sms", "MessageType": "SmsDeliveryReport", "MessageID": "4C0FWFWE86EE492ABCD34534122hJKHKHFDW" }

The possible values of StatusCodes are:

  • 1 - Delivered
  • 2 - Queued
  • 3 - Accepted
  • 4 - Failed
  • 5 - Rejected
  • 6 - Expired

The possible values of ErrorValues are:

  • 1 - Unknown
  • 2 - Absent Subscriber - Temporary
  • 3 - Absent Subscriber - Permanent
  • 4 - Call Barred by User
  • 5 - Portability Error
  • 6 - Anti-Spam Rejection
  • 7 - Handset Busy
  • 8 - Network Error
  • 9 - Illegal Number
  • 10 - Illegal Message
  • 11 - Unroutable
  • 12 - Destination Unreachable
  • 13 - Subscriber Age Restriction
  • 14 - Number Blocked by Carrier
  • 15 - Prepaid Insufficient Funds
  • 16 - Gateway Quota Exceeded
  • 17 - Message Blocked by Provider
  • 50 - Entity Filter
  • 51 - Header Filter
  • 52 - Content Filter
  • 53 - Consent Filter
  • 54 - Regulation Error
  • 99 - General Error

Delivered: The "Delivered" status confirms that the message has successfully reached the recipient's mobile device. It means that the message has passed through all the necessary network channels and has been received by the recipient's phone. This status is a strong indicator that the intended recipient has the opportunity to read the message.

Queued: The "Queued" status indicates that the message is queued for delivery to the intended recipient. The message is still with the message processor.

Accepted: The "Accepted" status indicates that the message processor ran all checks succesfully, correct number format, valid content etc. The message will continue to be processed.

Failed: The "Failed" status indicates that the message was not successfully sent to the recipient. This could be due to a variety of reasons such as incorrect phone numbers, network issues, or the recipient's phone being turned off or out of service. When a message fails, it means that it never reached the intended recipient's device.

Rejected: The "Rejected" status indicates an error for example with the message, recipient phonenumber or missing registrations in the recipients country.

Expired: The expired status indicates that the message failed to be delivered within the SMS lifespan. And won’t be retried.

Inbound SMS

What is Inbound SMS?

Inbound SMS refers to text messages sent to your virtual number. These messages can be used for customer queries, feedback, or receiving confirmation codes, making it a versatile tool for enhancing communication with your audience.

You can receive inbound SMS messages directly to your virtual number and a registered webhook. You will need a virtual number and an active webhook. You can request a virtual number and the webhook configuration by filling out the support form.

inboundsms v2 (1)

Specification