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.

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": "60", // Seconds - should be at least 21 for international traffic "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. Note: for international messages this value should be at least 21

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.

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": "1760534022725", "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": "1760534024000", "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:

001 - UNKNOWN_ERROR
Unknown or unspecified error

002 - UNKNOWN_SUBSCRIBER
Recipient number/subscriber is unknown or invalid in mobile network

003 - SUBSCRIBER_BARRED_BLOCKED
Recipient is barred, blocked, illegal, suspended, or otherwise not allowed

004 - SERVICE_OPT_OUT_BLOCKED
Recipient has opted out or requested not to receive messages

005 - CHANNEL_NOT_SUPPORTED
Recipient/network/device cannot receive SMS or this channel

006 - TEMPORARY_HANDSET_UNAVAILABLE
Recipient handset is temporarily unavailable or busy

007 - ABSENT_SUBSCRIBER_PERM
Recipient is temporarily unreachable or out of coverage

008 - RECIPIENT_TEMP_UNREACHABLE
Recipient deregistered or permanently unavailable

009 - HANDSET_TEMP_ERROR
Temporary handset/SIM/storage issue

010 - HANDSET_PERM_ERROR
Permanent handset/SIM/device issue or unsupported message type

011 - NETWORK_ERROR
Network/system/operator failure

012 - NUMBER_PORTABILITY_ISSUE
Delivery failed because of a number portability issue

013 - NO_SUITABLE_ROUTE_INTERNAL
Provider could not find a suitable internal route

014 - NO_ROUTE_TO_RECIPIENT
No delivery route could be found

015 - ROUTE_ERROR_UNSPECIFIED
Delivery failed because of an unspecified routing error

016 - INVALID_REQUEST
Malformed request or invalid submission

017 - INVALID_MESSAGE_PARAMETER
Invalid message parameter or encoding/header/template issue

018 - SPAM_FILTERED
Blocked by anti-spam or safeguard controls

019 - CONTENT_NOT_ALLOWED
Content not permitted

020 - INSUFFICIENT_CREDIT
Insufficient credit/quota

021 - AGE_RESTRICTED
Blocked due to age or parental restrictions

022 - DND_OPT_OUT
Recipient opted out or in Do-Not-Disturb list

023 - QUOTA_LIMIT
Spend/quota/rate/conversation limit reached

024 - EXPIRED
Message validity expired before delivery

025 - THIRD_PARTY_ERROR
Failure at third party provider

026 - DLT_ENTITY_ID_INVALID
DLT entity-id is missing or invalid

027 - DLT_HEADER_ID_INVALID
DLT header ID is missing or invalid

028 - DLT_CONTENT_ID_INVALID
DLT content-id is missing or invalid

029 - DLT_CONSENT_NOT_AUTHORIZED
Required recipient consent is not authorized

030 - REGULATORY_ERROR_UNEXPECTED
Unexpected regulatory/compliance 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.

Delivery Receipt / Notification (DLR) Retry Policy

We try to send the DLR up to four times if it fails:

  • 1st attempt: Sent immediately when the status is available.

  • 2nd attempt: 60 seconds after the first attempt fails.

  • 3rd attempt: 120 seconds after the second attempt fails.

  • 4th (final) attempt: 240 seconds after the third attempt fails.

After four failed attempts, we stop retrying.

The StatusDateTime field in the notification shows the time when the delivery status was generated. It is always in epoch format.

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