This quick tutorial will guide you through sending messages via WhatsApp using the 2Chat API.
✅ Requirements
- A 2Chat account with a connected WhatsApp number.
- That’s it! You’re ready to go.
📌 Steps
- Create a 2Chat account and connect your WhatsApp number in the Channel section.
- Grab your API Key from here.
- Now, let’s send a message using Python!
🐍 Sending a WhatsApp Message with Python
Imagine you have a sender number (+5959123123) and want to message a recipient (+59594545). Here’s how you do it:
import requests
import json
url = "https://api.p.2chat.io/open/whatsapp/send-message"
payload = json.dumps({
"to_number": "+59594545",
"from_number": "+5959123123",
"text": "Hi!",
})
headers = {
'X-User-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=payload)
print(response.json()) # Check the response
🎯 That’s It!
With just a few lines of code, you’ve successfully sent a WhatsApp message via API. For more details and additional API functionalities, check out the official 2Chat API Docs.
Top comments (0)