Before you can get started, you need the following already set up:
Set all SMS API configuration settings.
- Python and a familiarity with how to create a new app.
Learn how to quickly send SMS messages in a Python application with the Sinch SMS API.
First, you must set up your Python application.
Create a new file named send-sms.py
and paste the provided "Send an SMS message" code into the file.
import requests
servicePlanId = ""
apiToken = ""
sinchNumber = ""
toNumber = ""
url = "https://us.sms.api.sinch.com/xms/v1/" + servicePlanId + "/batches"
payload = {
"from": sinchNumber,
"to": [
toNumber
],
"body": "Hello how are you"
}
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + apiToken
}
response = requests.post(url, json=payload, headers=headers)
data = response.json()
print(data)
Assign your values to the following parameters:
Parameter Your value servicePlanId
The service plan ID found on your Customer Dashboard. apiToken
The API token found on your Customer Dashboard. Click Show to reveal your API token. sinchNumber
Any number you've assigned to your Sinch account. Find the number on your Customer Dashboard by clicking the service plan ID link and scrolling to the bottom of the page. toNumber
The phone number to which you want to send the test SMS message. Double check that the region is correct on your base URL. Learn more about regional options here.
Save the file.
Now you can execute the code and send your test SMS message. Run the following command:
python send-sms.py
The code you used in the send-sms.py
file sends a POST request to the Sinch API /batches
endpoint to send the SMS message. Click here to learn more about the batches endpoint.
- Visit our API specification to test more endpoints.