Textlocal Logo

API Documentation

Send WhatsApp via bulk JSON API

To get access to the WhatsApp Business API, Get in touch with support support@textlocal.com

Resource URL

https://api.txtlocal.com/bulk_json

Sample Request

<?php

$messages = array(
    // Put parameters here such as force or test
    'send_channel' => 'whatsapp',
    'messages' => array(
        array(
            'number' => 447123456789,
            'template' => array(
                'id' => '12345',
                'merge_fields' => array(
                    'FirstName' => 'Aleisha',
                    'LastName' => 'Britt',
                    'Custom1' => 'Custom 1 field test',
                    'Custom2' => 'Custom 2 field test',
                    'Custom3' => 'Custom 3 field test',
                )
            ),
            array(
                'number' => 447987654321,
                'template' => array(
                    'id' => '12345',
                    'merge_fields' => array(
                        'FirstName' => 'Kerys',
                        'LastName' => 'Fletcher',
                        'Custom1' => 'Custom 1 field test',
                        'Custom2' => 'Custom 2 field test',
                        'Custom3' => 'Custom 3 field test',
                    )
                )
            )
        )
    )
);

// Prepare data for POST request
$data = array(
    'apikey' => 'Your API key',
    'data' => json_encode($messages)
);

// Send the POST request with cURL
$ch = curl_init('https://api.txtlocal.com/bulk_json/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

echo $response;

Caution: Some users opt to place their request inside a code loop, while testing we highly recommend setting the test parameter to true, as occasionally an infinite loop can occur and users can consume all their credits very quickly.

Parameters

data The JSON payload, "messages" and "send_channel" are required fields. send_channel must be set to whatsapp and each message array must include a number and template details (Can be found by logging into message under send > Templates and drafts, Please note that if a template has a merge field and no value is given it will default to a space.
send_channel Required parameter, Must be set to whatsapp, If not set defaults to SMS.
Login Parameters (Additional Information)
apiKey You can create these in your Messenger Control Panel (click here) for each application, and limit the usage of them by host IP Address.
Data Parameters—Optional parameters that can be included in the JSON data payload
force If included and set to false, this will not send any messages if 1 or more messages in the send fails for any reason. If not provided defaults to true.
test Set this field to true to enable test mode, no messages will be sent and your credit balance will be unaffected. If not provided defaults to false.

Sample Response

{
    "messages": [
        {
            "cost": 1,
            "balance": 100,
            "number": "447123456789",
            "template_id": 2530563,
            "body": "This is a test template #Custom1# #Custom2#"
        },
        {
            "cost": 1,
            "balance": 100,
            "number": "447987654321",
            "template_id": 2530563,
            "body": "This is a test template #Custom1# #Custom2#"
        }
    ],
    "balance_pre_send": 100,
    "total_cost": 1,
    "balance_post_send": 98,
    "status": "success"
}

Errors

Error Codes
4 No recipients specified.
5 No message content.
6 Message too long.
7 Insufficient credits.
8 Invalid schedule date.
9 Schedule date is in the past.
10 Invalid group ID.
11 Selected group is empty.
15 Invalid JSON string.
32 Invalid number format.
33 You have supplied too many numbers.
34 You have supplied both a group ID and a set of numbers.
43 Invalid sender name.
44 No sender name specified.
51 No valid numbers specified.
57 No messages found.
80 Invalid Template. The message given didn't match any approved templates on your account.
204 Invalid message content.
314 One or more messages failed to send. No messages sent.
600 Invalid channel
601 The WhatsApp product is not configured on the account.