Send an SMS

In this SMS API Quickstart, you'll learn how to send an SMS from your web application using the SMS API.

Step 1: Set up your test environment

To start testing with the official Python SDK for the SMS API, you need to first set up your test environment.

The following command will install MessageBird:

pip install messagebird

Now, let's create a send_sms.py file in your project directory.

Step 2: Send your first SMS

Next, enter your credentials and mobile number - as both the originator and recipient - to the snippet below and copy it to your send_sms.py file

import messagebird
client = messagebird.Client(ACCESS_KEY)
message = client.message_create(
'MessageBird',
'31XXXXXXXXX',
'Hi! This is your first message',
{ 'reference' : 'Foobar' }
)
Notification icon

You can access and manage your credentials in the MessageBird Developer Dashboard.

Now, run the following command line:

python send_sms.py

Good job! You’ve just sent your first SMS with the MessageBird SMS API!

Step 3: View the response

Now, let’s view MessageBird’s HTTP response to your API call. If the set up was correct, you'll receive a response similar to this:

{
'id' : 'e60a6f90453a19019c56ed6b20170831',
'href' : 'https://rest.messagebird.com/messages/e60a6f90453a19019c56ed6b20170831',
'direction' : 'mt',
'type' : 'sms',
'originator' : 'MessageBird',
'body' : 'Hi! This is your first message',
'reference' : 'Foobar',
'validity' : None,
'gateway' : 240,
'typeDetails' : {},
'datacoding' : 'plain',
'mclass' : 1,
'scheduledDatetime' : None,
'createdDatetime' : '2016-05-03 14:26:57',
'recipients' : [
'totalCount' : 1,
'totalSentCount' : 1,
'totalDeliveredCount' : 0,
'totalDeliveryFailedCount' : 0,
'items' : [
{
'recipient' : 31XXXXXXXXX,
'status' : 'sent',
'statusDatetime' : '2016-05-03 14:26:57',
},
]
]
}

If something went wrong, you’ll receive an error response from the MessageBird API. Don't worry, simply head over to the SMS API Troubleshooting to understand the error.

Congrats! You can now programmatically send SMS with the MessageBird SMS API using Python.

Questions?

We’re always happy to help with code or other doubts you might have! Check out our Quickstarts, API Reference, Tutorials, SDKs, or contact our Support team.

Cookie Settings