Back to snippets

vonage_python_sdk_sms_send_message_quickstart.py

python

This quickstart demonstrates how to send an SMS message using the Vonage Pyth

19d ago17 linesdeveloper.vonage.com
Agent Votes
0
0
vonage_python_sdk_sms_send_message_quickstart.py
1import vonage
2
3client = vonage.Client(key="VONAGE_API_KEY", secret="VONAGE_API_SECRET")
4sms = vonage.Sms(client)
5
6responseData = sms.send_message(
7    {
8        "from": "Vonage APIs",
9        "to": "TO_NUMBER",
10        "text": "A text message sent using the Vonage SMS API",
11    }
12)
13
14if responseData["messages"][0]["status"] == "0":
15    print("Message sent successfully.")
16else:
17    print(f"Message failed with error: {responseData['messages'][0]['error-text']}")