SMS API
Send SMS
The send SMS API enables an application to send an SMS on behalf of the user and check the delivery status of a sent SMS.
To can send a SMS just making an authorized request to Bluevia APIs with the recipient and origin addresses and the text of the message.
Bear in mind the following limitations when sending SMS:
- SMS length is limited to 160 characters. Note that accented and special characters could count as two characters.
- International SMS are not allowed. Note that your application sends SMS on behalf of the user, so it is allowed to send messages only to phone numbers belonging to the user's country.
Your application can send the same SMS to several users including multiple recipient address elements.
Check delivery status
There are two ways of checking the delivery status of a sent SMS:
- Polling: Your application explicitly asks for the delivery status of a sent SMS.
- Notifications: Your application requests to be notified about the delivery status of a sent SMS.
Regardless of the method you use to check delivery status, you could get the following delivery status information:
- DeliveredToNetwork: The message has been delivered to the network. Another state could be available later to inform if the message was finally delivered to the handset.
- DeliveryUncertain: Delivery status unknown.
- DeliveryImpossible: Unsuccessful delivery; the message could not be delivered before it expired.
- MessageWaiting: The message is still queued for delivery. This is a temporary state, pending transition to another state.
- DeliveredToTerminal: The message has been successful delivered to the handset.
- DeliveryNotificationNotSupported: Unable to provide delivery status information because it is not supported by the network
Polling to check the delivery status
As stated above you can use Bluevia API to check the delivery status of a previous sent message. The delivery status of a sent SMS can be checked several times in order to get different status while the SMS is going through the network. When the SMS has been sent to multiple users the response to delivery status request includes as many delivery status elements as users the SMS was sent to.
Notifications to check the delivery status
If you provided a notification URL when sending the SMS you’ll receive a HTTP POST notification once the message has reached the final status. In this case please keep in mind the details about how notifications from Bluevia to the apps work (See the Authentication How to for more information http://link_to_howtos_authentication#when bluevia calls applications).
Note that although you are requesting delivery status notifications, you still are able to use the Location header to ask for delivery status following the polling strategy.
Receive SMS
This API enables an application to receive an SMS that the user sent to a shortcode. There are two ways of receiving the SMS in your application:
- Polling: Your application explicitly asks for the incoming SMS.
- Notifications: Your application requests to be notified each time a SMS is sent
Remember that users send SMS to your application sending a message to the [short number corresponding to their country http://link_to_shortcodes] and starting the message with the keyword you chose when requested the API key. Note that keywords are case-insensitive.
Bear in mind that your application doesn't need to run the OAuth process to get the user authorization to receive SMS, because this operation is not done on behalf of any user. You must use [2-legged OAuth http://link_to_howto/apiauth#application_not_acting_on_behalf_of_the_user]. This is an improvement in the latest versions of Bluevia APIs, but applications using 3-legged OAuth will keep working.
No matter how you receive the message you’ll get the origin address element containing either the phone number from which the message was sent, or an identifier (obfuscated sender) which represents the sender. This identifier can be used to answer the SMS.
Polling to receive SMS
To receive SMS messages sent to your application following a polling strategy make an authorized request indicating the short number corresponding to the user's country. Note that once your application has retrieved the messages, they are removed from the server.
Notifications to receive SMS
If you want to receive notifications about SMS sent to your applications you have to provide BlueVia with an URI where notifications must be sent. This URI is provided making a request to the inbound SMS subscription API. Please note that this subscription is for a specific shortcode and keyword. This creates a subscription to receive SMS sent to your application and in the response you’ll get a URL that can be used to stop receiving notifications.
Once your application has subscribed to received SMS notifications, BlueVia will send a notification to your application each time your application receives a SMS. This notification includes an Authorization header which should be used by your application to authenticate BlueVia (See the Authentication How to for more information http://link_to_howtos_authentication#when bluevia calls applications).
If you want to stop receiving notifications you have to unsubscribe your application making an authorized DELETE request to the URI you previously got during the subscription.
Operations
The following is the description of all operations, data types and error codes related to the SMS API. Data types are formally defined in the [SMS API XSD http://link_to_sms_schemas ](right click to download).
SendSMS
Allows an application to send a SMS.
Request
| URI | https://api.bluevia.com/services/REST/SMS/outbound/requests?version=v1 |
| HTTP method | POST |
| Authorization | OAuth [http://link_to_APIs_OAuth#Authenticated_API_Calls_From_Apps_to_Bluevia] |
| Body | smsText element of type SMSTextType, formatted as XML, JSON or URL encoded with the following structure:
|
Response
| HTTP status | 201 Created |
| HTTP headers | Location header, including the URI used to check delivery status. |
| Body | None |
Sending an SMS to one recipient:
Or to many recipients:
Note that Authorization header has been trimmed for clarity.
And the response:
Check SMS Delivery Status
Allows an application to check the delivery status of a sent SMS.
Request
| URI | Value of Location header from the Send SMS operation, followed by 'version=v1', and optionally 'alt=json' to request JSON format in the response. |
| HTTP method | GET |
| Authorization | OAuth [http://link_to_APIs_OAuth#Authenticated_API_Calls_From_Apps_to_Bluevia] |
| Body | None |
Response
| HTTP status | 200 OK |
| Body | smsDeliveryStatus element of type SMSDeliveryStatusType, formatted as XML or JSON (if 'alt=json' was included in the request) with the following structure:
|
Response if the SMS was sent to one recipient:
Or if it was sent to many recipients:
Notify SMS Delivery Status Update
Allows BlueVia to notify your application about changes in SMS delivery status.
Request
| URI | Value included in receiptRequest.endpoint from the Send SMS operation. |
| HTTP method | POST |
| Authorization | OAuth [http://link_to_APIs_OAuth#Authenticated_API_Calls_From_Bluevia_to_Apps] |
| Body | smsDeliveryStatusUpdate element of type SMSDeliveryStatusUpdateType, in the same format used in the Send SMS operation, that is, with the following structure:
|
Response
| HTTP status | 204 No Content |
| Body | None |
The notification from Bluevia (note that it’s XML):
And the response from your application to Bluevia:
Get Received SMS
Allows an application to get the received SMS sent to the application.
Request
| URI | https://api.bluevia.com/services/REST/SMS/inbound/{registrationId}/messages?version=v1, optionally followed by 'alt=json' to request JSON format in the response, where {registrationId} is the [short number corresponding to the user's country http://link_to_short_codes]. |
| HTTP method | GET |
| Authorization | OAuth |
| Body | None |
A sample request:
Response
| HTTP status | 200 OK or 204 No Content (when no SMS are available). |
| Body | If there is any SMS available, a receivedSMS element of type SMSMesageType or ReceivedSMSType (depending if there is only one or more than one SMS), formatted as XML or JSON (if 'alt=json' was included in the request) with the following information:
A 204 No Content HTTP status with no body is also a right response, indicating that no messages have been received. |
The response with one received message and obfuscated sender:
Or the body with more than one received message and non obfuscated sender:
Subscribe to Received SMS
Allows an application to subscribe itself to receive notifications about received SMS sent to the application.
Request
| URI | https://api.bluevia.com/services/REST/SMS/inbound/subscriptions?version=v1 |
| HTTP method | POST |
| Authorization | OAuth |
| Body | smsNotification element of type SMSNotificationType, formatted as XML, JSON or URL encoded. |
The subscription to the notifications:
Response
| HTTP status | 201 Created |
| HTTP headers | Location header, including the URI used to stop received SMS notifications (Unsubscribe to Received SMS operation). |
| Body | None |
The corresponding response:
Notify Received SMS
Allows BlueVia to notify your application when a new SMS sent to your applications is available.
Request
| URI | Value included in reference.endpoint from the Subscribe to Received SMS operation. |
| HTTP method | POST |
| Authorization | OAuth |
| Body | receivedSMSAsync element of type ReceivedSMSAsyncType, in the same format used in the Subscribe to Received SMS operation. |
Once you are subscribed you’ll receive notifications like this one:
Response
| HTTP status | 204 No Content |
| Body | None |
You’ll respond:
Unsubscribe to Received SMS
Allows an application to unsubscribe itself from receiving notifications about received SMS sent to the application.
Request
| URI | Value of Location header from the Subscribe to Received SMS operation, followed by 'version=v1'. |
| HTTP method | DELETE |
| Authorization | OAuth |
| Body | None |
In order to unsubscribe the request is:
Response
| HTTP status | 204 No Content |
| Body | None |
And the response:
Types
SMSTextType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| address | UserIdType | Y | The phone number to which the message will be sent, included as a phoneNumber element in UserIdType. Several address elements can be included when the SMS is sent to multiple users. It can also take the value of a obfuscated sender, including it as an alias element in UserIdType. |
| message | string | Y | The message text. |
| receiptRequest | SimpleReferenceType | N | Used to request delivery status notifications. |
| originAddress | UserIdType | Y | The access token of the user who is using the application, included as an alias element in UserIdType. |
SMSDeliveryStatusType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| smsDeliveryStatus | DeliveryInformationType | N | A list of delivery status information corresponding to the phone numbers to which the message was sent. |
SMSDeliveryStatusUpdateType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| correlator | string | Y | The value used in receiptRequest.correlator in theSMSTextType |
| deliveryStatus | DeliveryInformationType | Y | The delivery status information. |
ReceivedSMSType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| receivedSMS | SMSMessageType | N | A list of receivedSMS elements with the information of the received SMS. |
SMSNotificationType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| reference | SimpleReferenceType | Y | Used to indicate the correlator and URI to use in the Notify Received SMS operation. |
| destinationAddress | UserIdType | Y | The short number corresponding to the user's country, included as a phoneNumber in UserIdType. |
| criteria | string | Y | The keyword associated to the application. |
ReceivedSMSAsyncType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| correlator | string | Y | The value used in reference.correlator in the SMSNotificationType. |
| message | SMSMessageType | Y | The message information. |
DeliveryInformationType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| address | UserIdType | Y | Phone number to which the delivery status information is related to, included as a phoneNumber element in UserIdType. |
| deliveryStatus | DeliveryStatusType | Y | The delivery status. |
| description | string | N | Additional information about the delivery status. |
This enumeration has the following values:
| Value | Description |
|---|---|
| DeliveredToNetwork | The message has been delivered to the network. Another state could be available later to inform if the message was finally delivered to the handset. |
| DeliveryUncertain | Delivery status unknown. |
| DeliveryImpossible | Unsuccessful delivery; the message could not be delivered before it expired. |
| MessageWaiting | The message is still queued for delivery. This is a temporary state, pending transition to another state. |
| DeliveredToTerminal | The message has been successful delivered to the handset. |
| DeliveryNotificationNotSupported | Unable to provide delivery status information because it is not supported by the network. |
SMSMessageType
This type has the following structure:
| Name | Type | Required | Description |
|---|---|---|---|
| message | string | Y | The text of the received message. |
| originAddress | UserIdType | Y | The phone number from which the message was sent, included as a phoneNumber element inUserIdType. It can also take the value of an obfuscated sender, included as an alias element inUserIdType. |
| destinationAddress | UserIdType | Y | The short number to which the message was sent, included as a phoneNumber element in UserIdType. |
| dateTime | dateTime | N | The date and time when the message was sent. |
Error handling
Find below the error codes related to SMS API, following the BlueVia error format. You might need also the full list of [responses and generic error codes http://link_to_responses_and_common_errors].
| HTTP status | Category | Id | Description |
|---|---|---|---|
| 400 | SVC | 1 | Generic Client Error: The request format does not match Content-Type |
| 400 | SVC | 2 | Invalid parameter value: Content-Type |
| 400 | SVC | 2 | Invalid parameter value: address |
| 400 | SVC | 2 | Invalid parameter value: endpoint |
| 400 | SVC | 2 | Invalid parameter value: originAddress |
| 400 | SVC | 2 | Invalid parameter value: encode |
| 400 | SVC | 2 | Invalid parameter value: sourceport |
| 400 | SVC | 2 | Invalid parameter value: destinationport |
| 400 | SVC | 2 | Invalid parameter value: esm_class |
| 400 | SVC | 2 | Invalid parameter value: data_coding |
| 400 | SVC | 2 | Invalid parameter value: alt |
| 400 | SVC | 2 | Invalid parameter value: filterCriteria |
| 400 | SVC | 2 | Invalid parameter value: destinationAddress |
| 400 | SVC | 2 | Invalid parameter value: Criteria |
| 400 | SVC | 5 | Correlator specified in message part putNotificationCriteria is a duplicate |
| 400 | SVC | 1000 | Missing mandatory parameter: version |
| 400 | SVC | 1000 | Missing mandatory parameter: address |
| 400 | SVC | 1000 | Missing mandatory parameter: originAddress |
| 400 | SVC | 1000 | Missing mandatory parameter: endpoint |
| 400 | SVC | 1000 | Missing mandatory parameter: correlator |
| 400 | SVC | 1000 | Missing mandatory parameter: sourceport |
| 400 | SVC | 1000 | Missing mandatory parameter: destinationport |
| 400 | SVC | 1000 | Missing mandatory parameter: esm_class |
| 400 | SVC | 1000 | Missing mandatory parameter: data_coding |
| 400 | SVC | 1000 | Missing mandatory parameter: reference |
| 400 | SVC | 1000 | Missing mandatory parameter:destinationAddress |
| 400 | SVC | 1003 | Requested Operation does not exist |
| 400 | SVC | 1004 | Requested version of API is deprecated. Use v1/V1 |
| 400 | SVC | 1010 | Invalid Notifications endpoint: Use of SSL (HTTPS) for notifications is mandatory |
| 400 | SVC | 1011 | Invalid endpoint length. Length should be less than 150 characters |
| 400 | SVC | 1011 | Invalid correlator length. Length should be less than 20 characters |
| 400 | SVC | 1012 | Invalid endpoint format. Allowed Charset is [a-zA-z]+://[\\w\\/\\_\\.\\+\\?\\&\\=\\:\\-]*"}} |
| 400 | SVC | 1012 | Invalid correlator format. Allowed Charset is ^[A-Za-z0-9\\_]+$"}} |
| 400 | SVC | 3000 | The input parameter message is invalid (i.e. the message includes invalid characters) |
| 401 | SEC | 1004 | Invalid Token: delivery status retrieval not allowed for this token (i.e. when asking for a sms delivery status not sent by related user) |
| 401 | SEC | 1004 | Invalid Token: The oauth_Token's guid doesn't equals originAddress's guid (i.e. when sender of the sms does not match Access Token) |
| 401 | SEC | 1010 | Invalid consumer signature. Consumer authentication failed. |
| 403 | POL | 3302 | Maximum number of destination addresses 5 for exceeded in message |
| 403 | POL | 3303 | Maximum message length 160 exceeded in message |
| 403 | SVC | 1009 | Quota Exceeded (i.e. not enough credit in user account) |
| 404 | SVC | 1002 | Requested URI does not exist |
| 404 | SVC | 1007 | Registration Identifier does not exist |