API Code Examples
Get started quickly with ready-to-use snippets in Node.js and Python.
Explore code examples demonstrating how to authenticate and send WhatsApp messages using the AutomateIt REST API.
1. Node.js (Axios / Fetch)
Send a template message via Node.js:
// Install axios: npm install axios
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const baseUrl = 'https://api.automateit.rockybits.com/v1';
async function sendTemplateMessage() {
try {
const response = await axios.post(
`${baseUrl}/messages`,
{
to: '2348012345678', // Recipient phone number
type: 'template',
template: {
name: 'welcome_template',
language: {
code: 'en'
},
components: [
{
type: 'body',
parameters: [
{ type: 'text', text: 'Chidi' }
]
}
]
}
},
{
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
}
);
console.log('Message sent successfully:', response.data);
} catch (error) {
console.error('API Error:', error.response ? error.response.data : error.message);
}
}
sendTemplateMessage();
2. Python (Requests)
Send a text message via Python:
# Install requests: pip install requests
import requests
import json
api_key = "YOUR_API_KEY"
url = "https://api.automateit.rockybits.com/v1/messages"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
payload = {
"to": "2348012345678",
"type": "text",
"text": {
"body": "Hello from python requests!"
}
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
print("Success:", response.json())
else:
print("Error:", response.status_code, response.text)
Was this page helpful?