Skip to content
Last updated

Sending the XMS SMS API using Python

Heads up!

You're on an older page that may not be updated with the latest info. Click here to get started with the latest version of the SMS REST API.

In this tutorial we're going to utilize our HTTP REST Messaging API. Wow that's a beautiful name, right? Let us just call it XMS API, that feels a lot better!

Prerequisites

  1. You have created your Sinch account, if you don't have one, create one here and get some free credits to try the API out :fire:
  2. You have python and pip installed. If you don't, you can read about how to do it on your system here and for pip here.
  3. Install the Sinch Library (clx-sdk-sms, it's a legacy name :cocktail:). pip install clx-sdk-xms

Credentials

If you don't already have an API configured, go to your API Overview and click on the Add new REST API button. Your credentials will be generated and shown within seconds!

  1. Login to the dashboard.
  2. Go to your API Overview and find your Service Plan ID and API Token. Keep them close, we'll need them later.

Time to code!

Let us first set up our # Variables for the requestbody sender_phonenumber = '24321432' recipients_phonenumbers = ['213353455','+4623454645'] body = 'Hello, ${name}!' parameters = { 'name': { '+46722324894' : 'John', 'default' : 'valued customer' } }

try: message_params = api.MtBatchTextSmsCreate() message_params.sender = sender_phonenumber message_params.recipients = recipients_phonenumbers message_params.parameters = parameters message_params.body = body batch = client.create_batch(message_params) print('The batch was given ID %s' % batch.batch_id) except Exception as ex: print('Error creating batch: %s' % str(ex))