Sandbox (Test API Key)
The document explains how to use our WhatsApp Sandbox Environment.
We provide a developer-friendly test environment, for anyone that wants to explore the usage of our WhatsApp API. The WhatsApp API allows for direct-like access to the WhatsApp Business API. In the test environment, you can test sending messages and templates. The Sandbox is hosted in the Cloud API.
Limitations
What you can do in the Sandbox
You can use the Test API-KEY to send
textmessages andtexttemplates to your own phone number.An unlimited amount of messages can be sent with the sandbox.
Your phone number acts like a user and can send and receive messages.
The number can be a landline number, as long it is able to use WhatsApp.
You can switch the endpoint at any time. If you don't have one yet you can use a free service like RequestBin to set up an endpoint.
Each Sandbox API Key is linked to one phone number and you can only send test messages to that phone number. If you wish to test messages with more than 1 number then it is advised to set up a test WhatsApp Business Account (Staging WABA) to use instead of the Sandbox.
What you can't do with the Sandbox
The Sandbox is a test environment only. You will not be able to use it to send messages to your clients. You can only send messages to your own phone number.
Templates messages can be sent a maximum of 10 times. You can choose between 2 predefined templates.
Messages and Templates can be sent only to your own phone number.
We will only forward and trigger an API when your given number is involved.
We do not yet provide response information when you use the WhatsApp API.
You only have access to the WhatsApp API.
Our Sandbox is available to test via the API, but any automated tests would have to be configured from your end.
Send Template Message
POST https://waba-sandbox.360dialog.io/v1/messages
Headers
D360-API-KEY
(string)
Sandbox API KEY
gJSVEzk2Hh4x
Request Body
to
(number)
Your number
gHl4MCVdYUib
type
(string)
Message type
ELKfZ2H5yW2y
namespace
(string)
Template namespace
2i5r8y8iifgW
language
(string)
Template language
90btM6Zo81Se
policy
(string)
Delivery policy
s4BpPFJGGi5a
code
(string)
Language code
rnYiY0y5jTDG
name
(string)
Template name
45KqHij9Rt80
{
"messages": [
{
"id": "message_id"
}
],
"meta": {
"api_status": "stable",
"version": "2.35.4"
}
}Example Request Payload
first_welcome_messsage
{
"to": "1234567890",
"messaging_product": "whatsapp",
"type": "template",
"template": {
"name": "first_welcome_messsage",
"language": {
"code": "en"
},
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Placeholder 1"
}
]
}
]
}
}Note that this example covers first_welcome_messsage with personalization. In the case of the disclaimer template, the payload is similar but without the componentsobject (it holds personalization parameters which are not used in disclaimer).
{
"to": "1234567890",
"messaging_product": "whatsapp",
"type": "template",
"template": {
"name": "disclaimer",
"language": {
"code": "en"
},
"components": []
}
}{
"to": "1234567890",
"messaging_product": "whatsapp",
"type": "template",
"template": {
"name": "interactive_template_sandbox",
"language": {
"code": "en"
},
"components": [
{
"type": "button",
"sub_type": "quick_reply",
"index": 0,
"parameters": [
{
"type": "payload",
"payload": "aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 1,
"parameters": [
{
"type": "payload",
"payload": "aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT"
}
]
}
]
}
}Get new Sandbox API Key
You may recreate / get a new Sandbox API Key at any time by re-sending a WhatsApp message with content START to number 4930609859535. When you create a new API Key for your WhatsApp Number any existing Sandbox Keys associated with your number will be revoked.
Code Examples For Developers
Python
Creating an API key
Send a WhatsApp message START to the number 4930609859535. In the following examples, we assume your phone number is 49YOURNUMBER. Save the D360-API-KEY (in the examples it is described as YOUR_API_KEY).
Setting your Callback URL (optional)
Use an external service (such as requestbin.com) to test webhook responses, or create your own webhook server for tests. In the case you want to test with localhost, you may use an external service (such as ngrok).
#!/usr/bin/env python3
# coding: utf-8
import requests
url = "https://waba-sandbox.360dialog.io/v1/configs/webhook"
payload = '''
{
"url": "https://your-webhook-adress"
}
'''
headers = {
'D360-Api-Key': "YOUR_API_KEY",
'Content-Type': "application/json",
}
response = requests.post(url, data=payload, headers=headers)
print(response.status_code)
print(response.json())Now you may send any messages to the number 4930609859535. You will receive all webhooks as described in the WhatsApp API Webhooks Page.
For example, when you send a message with content abcd you will receive a message:
{
"contacts": [
{
"profile": {
"name": "Your name"
},
"wa_id": "49YOURNUMBER"
}
],
"messages": [
{
"from": "49YOURNUMBER",
"id": "ABGGSHggVwIvAhANFj5aqzEi_lbauSkLYDCO",
"text": {
"body": "abcd"
},
"timestamp": "1591955533",
"type": "text"
}
]
}
Test sending messages
#!/usr/bin/env python3
# coding: utf-8
import requests
url = "https://waba-sandbox.360dialog.io/v1/messages"
payload = '''
{
"to": "49YOURNUMBER",
"type": "text",
"text": {
"body": "Any message you want..."
}
}
'''
headers = {
'D360-Api-Key': "YOUR_API_KEY",
'Content-Type': "application/json",
}
response = requests.post(url, data=payload, headers=headers)
print(response.status_code)
print(response.json())In your webhook, you will receive messages about status updates. For example:
{
"statuses": [
{
"id": "gBGGSHggVwIvAgk4hwKJv9PdlG4",
"recipient_id": "49YOURNUMBER",
"status": "read",
"timestamp": "1591955668"
}
]
}Test sending templates
#!/usr/bin/env python3
# coding: utf-8
import requests
url = "https://waba-sandbox.360dialog.io/v1/messages"
payload = '''
{
"to": "49YOURNUMBER",
"type": "template",
"template": {
"namespace": "c8ae5f90_307a_ca4c_b8f6_d1e2a2573574",
"language": {
"policy": "deterministic",
"code": "de"
},
"name": "first_welcome_messsage",
"components": [{
"type": "body",
"parameters": [{
"type": "text",
"text": "YOUR NAME"
}
]
}
]
}
}
'''
headers = {
'D360-Api-Key': "YOUR_API_KEY",
'Content-Type': "application/json",
}
response = requests.post(url, data=payload, headers=headers)
print(response.status_code)
print(response.json())Similarly to sending text messages, you will receive webhook calls with status updates.
PHP
Creating an API key
Send a WhatsApp message START to the number 4930609859535. In the following examples, we assume your phone number is 49YOURNUMBER. Save API Key (in examples will be YOUR_API_KEY).
Setting your webhook (optional)
Use external service e.g. requestbin.com to test webhook answers. Or create your own webhook server for tests. In case if you want to test with localhost you may use e.g. external ngrok.com service.
Then set your webhook:
<?php
$url = "https://waba-sandbox.360dialog.io/v1/configs/webhook";
$payload = <<<'PAYLOAD'
{
"url": "https://your-webhook-adress"
}
PAYLOAD;
$headers = [
"Content-Type: application/json",
"D360-Api-Key: YOUR_API_KEY",
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => $headers,
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "curl error: " . $err;
} else {
echo $response;
}Now you may send any messages to the number 4930609859535. You will receive all webhooks as described in the WhatsApp API Webhooks Page.
For example, when you send a message with content abcd you will receive a message:
{
"contacts": [
{
"profile": {
"name": "Your name"
},
"wa_id": "49YOURNUMBER"
}
],
"messages": [
{
"from": "49YOURNUMBER",
"id": "ABGGSHggVwIvAhANFj5aqzEi_lbauSkLYDCO",
"text": {
"body": "abcd"
},
"timestamp": "1591955533",
"type": "text"
}
]
}
Test sending messages
<?php
$url = "https://waba-sandbox.360dialog.io/v1/messages";
$payload = <<<'PAYLOAD'
{
"to": "49YOURNUMBER",
"type": "text",
"text": {
"body": "Any message you want..."
}
}
PAYLOAD;
$headers = [
"Content-Type: application/json",
"D360-Api-Key: YOUR_API_KEY",
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => $headers,
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "curl error: " . $err;
} else {
echo $response;
}In your webhook, you will receive messages about status updates. For example:
{
"statuses": [
{
"id": "gBGGSHggVwIvAgk4hwKJv9PdlG4",
"recipient_id": "49YOURNUMBER",
"status": "read",
"timestamp": "1591955668"
}
]
}Test sending templates
<?php
$url = "https://waba-sandbox.360dialog.io/v1/messages";
$payload = <<<'PAYLOAD'
{
"to": "49YOURNUMBER",
"type": "template",
"template": {
"language": {
"policy": "deterministic",
"code": "de"
},
"name": "first_welcome_messsage",
"components": [{
"type": "body",
"parameters": [{
"type": "text",
"text": "YOUR NAME"
}
]
}
]
}
}
PAYLOAD;
$headers = [
"Content-Type: application/json",
"D360-Api-Key: YOUR_API_KEY",
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => $headers,
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "curl error: " . $err;
} else {
echo $response;
}Similarly to sending text messages you will receive webhook calls with status updates.
CURL
Creating API Key
Send a WhatsApp message START to the number 4930609859535. In the following examples, we assume your phone number is 49YOURNUMBER. Save API Key (in the examples will be YOUR_API_KEY).
Setting your webhook (optional)
Use external service e.g. requestbin.com to test webhook answers, or create your own webhook server for tests. In the case you want to test with localhost you may use e.g. external ngrok.com service.
Then set your webhook:
curl --request POST \
--url https://waba-sandbox.360dialog.io/v1/configs/webhook \
--header 'Content-Type: application/json' \
--header 'D360-Api-Key: YOUR_API_KEY' \
--data '{"url": "https://your-webhook-adress"}'Now you may send any messages to the number 4930609859535. You will receive all webhooks as described in WhatsApp API https://developers.facebook.com/docs/whatsapp/api/webhooks
For example, when you send a message with content abcd you will receive the message:
{
"contacts": [
{
"profile": {
"name": "Your name"
},
"wa_id": "49YOURNUMBER"
}
],
"messages": [
{
"from": "49YOURNUMBER",
"id": "ABGGSHggVwIvAhANFj5aqzEi_lbauSkLYDCO",
"text": {
"body": "abcd"
},
"timestamp": "1591955533",
"type": "text"
}
]
}
Test sending messages
curl --request POST \
--url https://waba-sandbox.360dialog.io/v1/messages \
--header 'Content-Type: application/json' \
--header 'D360-Api-Key: YOUR_API_KEY' \
--data '{"to":"49YOURNUMBER","type":"text","text":{"body":"Any message you want..."}}'In your webhook, you will receive messages about status updates. For example:
{
"statuses": [
{
"id": "gBGGSHggVwIvAgk4hwKJv9PdlG4",
"recipient_id": "49YOURNUMBER",
"status": "read",
"timestamp": "1591955668"
}
]
}Test sending templates
curl --request POST \
--url https://waba-sandbox.360dialog.io/v1/messages \
--header 'Content-Type: application/json' \
--header 'D360-Api-Key: YOUR_API_KEY' \
--data '{"to": "1234567890", "messaging_product": "whatsapp", "type": "template", "template": { "name": "first_welcome_messsage", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "Placeholder 1"}'Similarly to sending text messages, you will receive webhooks with status updates.
Last updated
Was this helpful?