Getting started

Sending messages

By now you should be able to connect to the API, issue requests and receive responses. You can now send your first SMS message using the API.

This process is very similar to the previous request you executed to test your connectivity, but instead of using a HTTP GET to retrieve information, this time you’re going to use a HTTP POST to ask Whispir to do something.

Because you’re sending a message you need to tell Whispir who to send it to, and what type of content it is.

You’re going to use the URL https://api.<region>.whispir.com/messages as the API endpoint.

Specifying the content type

The next thing you need to do is tell Whispir what information you’re sending. You can send any XML or JSON content, but it’s better if Whispir knows exactly what you’re sending.

Tell Whispir what you’re sending by using the Content-Type HTTP header. Your Content-Type header is going to be (either JSON or XML):

  • application/vnd.whispir.message-v1+json
  • application/vnd.whispir.message-v1+xml

This tells Whispir that you’re sending content that conforms to Version 1 of the message schema. As Whispir adds more features to each schema, our version numbers will increase.

The headers are unique for each endpoint. They are detailed in the specific endpoint sections in this document. Also see Content types and versioning for the complete list.

Sending messages using JSON and XML

Once you’ve successfully sent your SMS message using cURL, you can move on to using your application to generate XML or JSON formats for processing.

Be sure to include the correct headers for the desired content type:

  • XML: application/vnd.whispir.message-v1+xml
  • JSON: application/vnd.whispir.message-v1+json

For more information on messages and all the other Whispir resources, continue through this documentation, or jump to Messages.

  • JSON
  • XML

Sending messages

Send your first message using cURL.

{{codeStart}}

curl -H "Authorization: Basic <YOUR AUTH HEADER>"

-H "x-api-key: <YOUR API KEY>"

-H "Content-Type: application/vnd.whispir.message-v1+json"

-H "Accept: application/vnd.whispir.message-v1+json"

-d '{

"to": "<DESTINATION PHONE NUMBER(S)>",

"subject": "This is the first line of my SMS",

"body": "This is the content of my SMS"

}'

https://api.<region>.whispir.com/messages?apikey=<YOUR API KEY>

{{codeEnd}}

Once you submit this Whispir will send you back a HTTP 202 Accepted message stating that your request has been accepted for processing.

Within a few seconds your phone should be buzzing away.

 

Samples in XML/JSON

The following example shows how to use a POST request to send the message in XML or JSON. Use the selector at the top to choose your syntax.

{{codeStart}}

POST https://api.<region>.whispir.com/messages?apikey=89asdfohasd89023rsd

Authorization: Basic am9obi5zbWl0aDpteXBhc3N3b3Jk

x-api-key: 89asdfohasd89023rsd

Content-Type: application/vnd.whispir.message-v1+json

Accept: application/vnd.whispir.message-v1+json

{

"to": "<DESTINATION PHONE NUMBER>",

"subject": "This is the first line of my SMS",

"body": "This is the content of my SMS"

}

{{codeEnd}}