Skip to content

Code Examples

Copy-ready WhatsGate API examples in cURL, JavaScript, PHP, Python, and C#. Replace every placeholder locally and keep API tokens on the server side.

Placeholders

PlaceholderMeaning
{subdomain}Your tenant subdomain
{api_token}API token from your dashboard
{sender_device}The connected WhatsApp device mobile number
{recipient_phone}Recipient phone number

Send A Text Message

bash
curl -X POST "https://{subdomain}.whatsgate.net/api/send/text" \
  -H "Access-Token: {api_token}" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "sender_device": "{sender_device}",
    "phone": "{recipient_phone}",
    "message": "Hello from WhatsGate"
  }'
js
const response = await fetch('https://{subdomain}.whatsgate.net/api/send/text', {
  method: 'POST',
  headers: {
    'Access-Token': '{api_token}',
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    sender_device: '{sender_device}',
    phone: '{recipient_phone}',
    message: 'Hello from WhatsGate',
  }),
});

const result = await response.json();
console.log(result);
php
<?php

$payload = [
    'sender_device' => '{sender_device}',
    'phone' => '{recipient_phone}',
    'message' => 'Hello from WhatsGate',
];

$ch = curl_init('https://{subdomain}.whatsgate.net/api/send/text');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Access-Token: {api_token}',
        'Accept: application/json',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
python
import requests

response = requests.post(
    "https://{subdomain}.whatsgate.net/api/send/text",
    headers={
        "Access-Token": "{api_token}",
        "Accept": "application/json",
        "Content-Type": "application/json",
    },
    json={
        "sender_device": "{sender_device}",
        "phone": "{recipient_phone}",
        "message": "Hello from WhatsGate",
    },
    timeout=30,
)

print(response.json())
csharp
using System.Net.Http.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Access-Token", "{api_token}");
client.DefaultRequestHeaders.Add("Accept", "application/json");

var response = await client.PostAsJsonAsync(
    "https://{subdomain}.whatsgate.net/api/send/text",
    new
    {
        sender_device = "{sender_device}",
        phone = "{recipient_phone}",
        message = "Hello from WhatsGate",
    }
);

Console.WriteLine(await response.Content.ReadAsStringAsync());

Successful response:

json
{
  "success": true,
  "message": "Message will be sent to 1 phone numbers"
}

Send An Image Message

bash
curl -X POST "https://{subdomain}.whatsgate.net/api/send/image" \
  -H "Access-Token: {api_token}" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "sender_device": "{sender_device}",
    "phone": "{recipient_phone}",
    "media": "https://example.com/image.jpg",
    "caption": "Image from WhatsGate"
  }'
js
const response = await fetch('https://{subdomain}.whatsgate.net/api/send/image', {
  method: 'POST',
  headers: {
    'Access-Token': '{api_token}',
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    sender_device: '{sender_device}',
    phone: '{recipient_phone}',
    media: 'https://example.com/image.jpg',
    caption: 'Image from WhatsGate',
  }),
});

console.log(await response.json());
php
<?php

$payload = [
    'sender_device' => '{sender_device}',
    'phone' => '{recipient_phone}',
    'media' => 'https://example.com/image.jpg',
    'caption' => 'Image from WhatsGate',
];

$ch = curl_init('https://{subdomain}.whatsgate.net/api/send/image');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Access-Token: {api_token}',
        'Accept: application/json',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
]);

echo curl_exec($ch);
curl_close($ch);
python
import requests

response = requests.post(
    "https://{subdomain}.whatsgate.net/api/send/image",
    headers={
        "Access-Token": "{api_token}",
        "Accept": "application/json",
    },
    json={
        "sender_device": "{sender_device}",
        "phone": "{recipient_phone}",
        "media": "https://example.com/image.jpg",
        "caption": "Image from WhatsGate",
    },
    timeout=30,
)

print(response.json())
csharp
using System.Net.Http.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Access-Token", "{api_token}");
client.DefaultRequestHeaders.Add("Accept", "application/json");

var response = await client.PostAsJsonAsync(
    "https://{subdomain}.whatsgate.net/api/send/image",
    new
    {
        sender_device = "{sender_device}",
        phone = "{recipient_phone}",
        media = "https://example.com/image.jpg",
        caption = "Image from WhatsGate",
    }
);

Console.WriteLine(await response.Content.ReadAsStringAsync());

Check Device Status

bash
curl "https://{subdomain}.whatsgate.net/api/status/{sender_device}" \
  -H "Access-Token: {api_token}" \
  -H "Accept: application/json"
js
const response = await fetch('https://{subdomain}.whatsgate.net/api/status/{sender_device}', {
  headers: {
    'Access-Token': '{api_token}',
    'Accept': 'application/json',
  },
});

console.log(await response.json());
php
<?php

$ch = curl_init('https://{subdomain}.whatsgate.net/api/status/{sender_device}');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Access-Token: {api_token}',
        'Accept: application/json',
    ],
]);

echo curl_exec($ch);
curl_close($ch);
python
import requests

response = requests.get(
    "https://{subdomain}.whatsgate.net/api/status/{sender_device}",
    headers={
        "Access-Token": "{api_token}",
        "Accept": "application/json",
    },
    timeout=30,
)

print(response.json())
csharp
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Access-Token", "{api_token}");
client.DefaultRequestHeaders.Add("Accept", "application/json");

var response = await client.GetAsync(
    "https://{subdomain}.whatsgate.net/api/status/{sender_device}"
);

Console.WriteLine(await response.Content.ReadAsStringAsync());

Read Device Balance

bash
curl "https://{subdomain}.whatsgate.net/api/reports/balance/{sender_device}" \
  -H "Access-Token: {api_token}" \
  -H "Accept: application/json"
js
const response = await fetch('https://{subdomain}.whatsgate.net/api/reports/balance/{sender_device}', {
  headers: {
    'Access-Token': '{api_token}',
    'Accept': 'application/json',
  },
});

console.log(await response.json());
php
<?php

$ch = curl_init('https://{subdomain}.whatsgate.net/api/reports/balance/{sender_device}');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Access-Token: {api_token}',
        'Accept: application/json',
    ],
]);

echo curl_exec($ch);
curl_close($ch);
python
import requests

response = requests.get(
    "https://{subdomain}.whatsgate.net/api/reports/balance/{sender_device}",
    headers={
        "Access-Token": "{api_token}",
        "Accept": "application/json",
    },
    timeout=30,
)

print(response.json())
csharp
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Access-Token", "{api_token}");
client.DefaultRequestHeaders.Add("Accept", "application/json");

var response = await client.GetAsync(
    "https://{subdomain}.whatsgate.net/api/reports/balance/{sender_device}"
);

Console.WriteLine(await response.Content.ReadAsStringAsync());

Get Failed Numbers

bash
curl "https://{subdomain}.whatsgate.net/api/reports/failed_numbers?device={sender_device}&from=2026-01-01&to=2026-01-31" \
  -H "Access-Token: {api_token}" \
  -H "Accept: application/json"
js
const url = new URL('https://{subdomain}.whatsgate.net/api/reports/failed_numbers');
url.searchParams.set('device', '{sender_device}');
url.searchParams.set('from', '2026-01-01');
url.searchParams.set('to', '2026-01-31');

const response = await fetch(url, {
  headers: {
    'Access-Token': '{api_token}',
    'Accept': 'application/json',
  },
});

console.log(await response.json());
php
<?php

$query = http_build_query([
    'device' => '{sender_device}',
    'from' => '2026-01-01',
    'to' => '2026-01-31',
]);

$ch = curl_init("https://{subdomain}.whatsgate.net/api/reports/failed_numbers?{$query}");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Access-Token: {api_token}',
        'Accept: application/json',
    ],
]);

echo curl_exec($ch);
curl_close($ch);
python
import requests

response = requests.get(
    "https://{subdomain}.whatsgate.net/api/reports/failed_numbers",
    headers={
        "Access-Token": "{api_token}",
        "Accept": "application/json",
    },
    params={
        "device": "{sender_device}",
        "from": "2026-01-01",
        "to": "2026-01-31",
    },
    timeout=30,
)

print(response.json())
csharp
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Access-Token", "{api_token}");
client.DefaultRequestHeaders.Add("Accept", "application/json");

var response = await client.GetAsync(
    "https://{subdomain}.whatsgate.net/api/reports/failed_numbers?device={sender_device}&from=2026-01-01&to=2026-01-31"
);

Console.WriteLine(await response.Content.ReadAsStringAsync());

Notes

  • REST API requests use Access-Token: {api_token}.
  • Tenant MCP client configuration uses Authorization: Bearer {api_token}.
  • Keep real tokens out of frontend code, public docs, screenshots, and support messages.

Released under the MIT License.