cURL Examples
Quick examples using cURL for testing and shell scripts.
Setup
Set your API key as an environment variable:
export GBCHAT_API_KEY="gbk_live_your_api_key_here"
Send Message
Basic Message (No Variables)
curl -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "hello_world",
"language": "en"
}'
Message with Variables
curl -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "order_confirmation",
"language": "en",
"variables": {
"1": "John Doe",
"2": "ORD-12345",
"3": "₹1,499"
}
}'
Message with External ID
curl -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "order_shipped",
"language": "en",
"variables": {
"1": "John Doe",
"2": "ORD-12345",
"3": "Feb 10, 2024"
},
"externalId": "order-12345"
}'
Using a Specific Account
curl -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "appointment_reminder",
"language": "en",
"variables": {
"1": "Dr. Smith",
"2": "Tomorrow at 10:00 AM"
},
"accountId": "67890abcdef12345"
}'
Response Examples
Successful Response
{
"success": true,
"data": {
"messageId": "msg_abc123xyz",
"waMessageId": "wamid.HBgLMTIzNDU2Nzg5MA==",
"status": "sent",
"to": "919876543210",
"template": "order_confirmation",
"externalId": "order-12345"
}
}
Error Response
{
"success": false,
"error": {
"code": "TEMPLATE_NOT_FOUND",
"message": "Template 'invalid_template' not found or not approved"
}
}
Shell Script Examples
Send Single Message
#!/bin/bash
# send-message.sh
# Usage: ./send-message.sh <phone> <template> <language> [var1] [var2] ...
PHONE="$1"
TEMPLATE="$2"
LANGUAGE="${3:-en}"
shift 3
# Build variables JSON
VARS_JSON="{"
INDEX=1
for VAR in "$@"; do
if [ $INDEX -gt 1 ]; then VARS_JSON+=","; fi
VARS_JSON+="\"$INDEX\":\"$VAR\""
INDEX=$((INDEX + 1))
done
VARS_JSON+="}"
# Send request
curl -s -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"to\": \"$PHONE\",
\"template\": \"$TEMPLATE\",
\"language\": \"$LANGUAGE\",
\"variables\": $VARS_JSON
}" | jq .
Usage:
./send-message.sh 919876543210 order_confirmation en "John Doe" "ORD-12345"
Batch Send from CSV
#!/bin/bash
# batch-send.sh
# CSV Format: phone,name,order_id
# Usage: ./batch-send.sh customers.csv
INPUT_FILE="$1"
TEMPLATE="order_confirmation"
DELAY=1 # seconds between messages
while IFS=, read -r phone name order_id; do
# Skip header row
if [ "$phone" == "phone" ]; then continue; fi
echo "Sending to $phone..."
RESPONSE=$(curl -s -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"to\": \"$phone\",
\"template\": \"$TEMPLATE\",
\"language\": \"en\",
\"variables\": {
\"1\": \"$name\",
\"2\": \"$order_id\"
},
\"externalId\": \"$order_id\"
}")
SUCCESS=$(echo "$RESPONSE" | jq -r '.success')
if [ "$SUCCESS" == "true" ]; then
MSG_ID=$(echo "$RESPONSE" | jq -r '.data.messageId')
echo " ✓ Sent: $MSG_ID"
else
ERROR=$(echo "$RESPONSE" | jq -r '.error.message')
echo " ✗ Failed: $ERROR"
fi
sleep $DELAY
done < "$INPUT_FILE"
echo "Batch complete!"
Example CSV (customers.csv):
phone,name,order_id
919876543210,John Doe,ORD-001
919876543211,Jane Smith,ORD-002
919876543212,Bob Wilson,ORD-003
Check Rate Limit
#!/bin/bash
# Check remaining rate limit from response headers
RESPONSE=$(curl -s -i -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "hello_world",
"language": "en"
}')
# Extract headers
LIMIT=$(echo "$RESPONSE" | grep -i "x-ratelimit-limit" | cut -d: -f2 | tr -d ' \r')
REMAINING=$(echo "$RESPONSE" | grep -i "x-ratelimit-remaining" | cut -d: -f2 | tr -d ' \r')
RESET=$(echo "$RESPONSE" | grep -i "x-ratelimit-reset" | cut -d: -f2 | tr -d ' \r')
echo "Rate Limit: $REMAINING / $LIMIT remaining"
echo "Resets at: $(date -d @$RESET)"
Debugging
Verbose Output
Use -v for detailed request/response info:
curl -v -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "hello_world",
"language": "en"
}'
Pretty Print Response
Pipe to jq for formatted JSON:
curl -s -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "hello_world",
"language": "en"
}' | jq .
Save Response to File
curl -s -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "hello_world",
"language": "en"
}' -o response.json
Common Errors
Invalid API Key
curl -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: invalid_key" \
-H "Content-Type: application/json" \
-d '{"to": "919876543210", "template": "hello_world", "language": "en"}'
Response:
{
"success": false,
"error": {
"code": "INVALID_API_KEY",
"message": "Invalid API key."
}
}
Missing Content-Type
# This will fail!
curl -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-d '{"to": "919876543210", "template": "hello_world", "language": "en"}'
Always include -H "Content-Type: application/json".
Invalid Phone Format
# Wrong: has + prefix
curl -X POST https://inboxapi.workmatic.in/api/v1/message/send \
-H "X-API-Key: $GBCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"to": "+919876543210", "template": "hello_world", "language": "en"}'
Remove the + prefix from phone numbers.