Receive Text Messages
With the TextMagic API, you can establish a full two-way communication pipeline for sending and receiving text messages within your application.
Incoming messages callback
A callback is a mechanism that posts the JSON body of a received message to the URL on a server that you specify. The server application which receives the callback can save the message data into a database, send user notifications, etc.
Here is how to set up the incoming messages callback URL:
- Log in to TextMagic (or start a free trial if you haven’t registered yet).
- Go to the API page.
- Enter your callback URL into the Callback URL for incoming messages field.
- Click the Test button to test your URL.
- If it’s successful, click Save changes.
Your server should reply with a 200 OK response at this URL. If it does not, your callback URL will be treated as invalid and the inbound messages will not be passed to your application.
Your callback URL will be triggered immediately after a message reaches the TextMagic server. The parameters are passed by the POST method and contain the following information (i.e. exact copy of the reply resource). The Resource format is basically the format of the reply when making the request to the specific API resource.
|id||Inbound message ID.|
|sender|| ||Sender phone number.|
|receiver|| ||Receiver phone number (i.e. your dedicated or shared reply number).|
|messageTime||The time when the message reached the TextMagic server.|
|text||Inbound message text.|
REST inbound messages management
You can also interact with the inbound messages (or to put it simply, the replies) just like with other REST resources, such as with the templates, messages, contacts, and so on.
Get all inbound messages
To get all the replies, use this URI:
with these parameters:
Fetch the specified results page. The default is 1.
|limit||No||The number of results per page. The default is 10.|
You will receive a standard paginated response:
|page||3||The current fetched page.|
|limit||25||The number of results per page.|
|pageCount||150||The total number of pages.|
|resources||Array of reply resources||See next section for reply resource format details.|
Get a single inbound message
To get a single inbound message, use:
where id is the unique numeric ID for the inbound message. This command has no parameters.
|id||The ID of the inbound message.|
|sender|| ||The sender’s phone number.|
|receiver|| ||The receiver’s phone number (i.e. your dedicated or shared reply number).|
|messageTime||The time when the message reached the TextMagic API endpoint.|
|text||The text from the received message.|
Delete a single inbound message
To delete an inbound message, use the following command:
where id is the unique numeric ID for the inbound message. This command takes no parameters. If successful, it will return the standard HTTP status code for a DELETE response (204 No Content). Otherwise, you’ll receive an HTTP error code and an error message.
Note, deleted inbound message will disappear from TextMagic Online, chats, and any other place they are referenced. So, be careful!