Schedule Text Messages
You can schedule text messages to be sent at a later date or time, or can create recurring text message sessions with Textmagic API. Below is a detailed overview of how to do both.
Schedule a message for sending once
Execute:
POST
using the same parameters as Messages: Send, but also add the scheduled time.
You may schedule sending messages by setting the sendingTime parameter using the UNIX timestamp format. That is the number of seconds since 1 January 1970, 00:00:00 UTC. To convert the date/time to UNIX timestamp, you can use this tool.
To send an SMS message with the text “Happy New Year!” to +447860021130 on 1 January 2016, 00:00:00 UTC, write:
POST api/v2/messages
with the following parameters:
Parameter
|
Value
|
---|---|
text | Happy New Year! |
phones |
447860021130
|
sendingTime | 1451606400 |
You will receive this response:
Parameter
|
Example
|
---|---|
id | 313 |
href | /api/v2/schedules/313 |
type | schedule |
sessionId | null |
bulkId | null |
messageId | null |
scheduleId | 313 |
As you can see, only the schedule field is filled. The other fields (such as session and messages) will be filled later.
Schedule a message for repeat-sending
You can also create a recurring message schedule. However, note, this is a bit tricky because you need to prepare an iCal RRULE string, so first, carefully read all the necessary string formatting rules.
As an example, let’s schedule a message to be sent 10 times a day. The corresponding RRULE string is:
FREQ=DAILY;INTERVAL=2;COUNT=5;
So you need to use:
POST
with the following parameters:
Parameter
|
Value
|
---|---|
text | Daily reminder |
phones |
447860021130
|
sendingTime | 1451606400 |
rrule | FREQ=DAILY;INTERVAL=2;COUNT=5; |
Note, the response is different from the previous example:
Parameter
|
Example
|
---|---|
id |
314
|
href | /api/v2/schedules/314 |
type | schedule |
sessionId | null |
bulkId | null |
messageId | null |
scheduleId |
314
|
Manage scheduled messages
You can also interact with the scheduled messages just like with the other REST resources (such as templates, messages, contacts, etc.).
Get all scheduled messages
To get all the scheduled messages, use:
GET /api/v2/schedules
with these parameters:
Name
|
Required?
|
Example
|
Description
|
---|---|---|---|
page | No |
3
|
Fetch specified results page. The default is 1. |
limit | No | 25 |
How many results to return. The default is 10. |
You will receive a standard paginated response:
Parameter
|
Example
|
Description
|
---|---|---|
page |
3
|
The current fetched page. |
limit | 25 |
The number of results per page. |
pageCount | 150 |
The total number of pages. |
resources | Array of schedule resources | See next section for schedule resource format details. |
Get a single scheduled message
To get a single scheduled message, use:
GET /api/v2/schedules/{id}
where id is a numeric schedule ID. Note, this command has no parameters.
The response is:
Parameter
|
Example
|
Description
|
---|---|---|
id |
562
|
Schedule ID. |
nextSend |
2014-10-13T05:00:00+0000
|
Next send date in ISO 8601 format. |
rrule |
FREQ=DAILY;INTERVAL=2;COUNT=5;
|
iCal RRULE string. |
session | Linked session resource | See Sessions section for the session format details. |
Delete a single scheduled message
To delete a scheduled message, use the following command:
DELETE /api/v2/schedules/{id}
where id is a numeric schedule ID. Note, this command has no parameters. If your request is successful, this command will return a standard delete response (204 No Content). Otherwise, you’ll receive the standard error response.
The next step
Congratulations! You can now use Textmagic API to manage and schedule text messages online. Please check the section on message Sessions to gain a better understanding of how messaging works.