API Send Message

Basic code for sending message through API

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.fonnte.com/send',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array(
'target' => '08123456789|Fonnte|Admin,08123456789|Lili|User',
'message' => 'test message to {name} as {var1}',
'url' => 'https://md.fonnte.com/images/wa-logo.png',
'filename' => 'filename',
'schedule' => '0',
'typing' => false,
'delay' => '2',
'countryCode' => '62',
'file' => new CURLFile("localfile.jpg"),
'location' => '-7.983908, 112.621391',
'buttonJSON' => '{"message":"fonnte button message","footer":"fonnte footer message","buttons":[{"id":"mybutton1","message":"hello fonnte"},{"id":"mybutton2","message":"fonnte pricing"},{"id":"mybutton3","message":"tutorial fonnte"}]}',
'templateJSON' => '{"message":"fonnte template message","footer":"fonnte footer message","buttons":[{"message":"fonnte","url":"https://fonnte.com"},{"message":"call me","tel":"6282227097005"},{"id":"mybutton1","message":"hello fonnte"}]}',
'listJSON' => '{"message":"fonnte list message","footer":"fonnte footer message","buttonTitle":"fonnte\'s packages","title":"fonnte title","buttons":[{"title":"text only","list":[{"message":"regular","footer":"10k messsages/month","id":"list-1"},{"message":"regular pro","footer":"25k messsages/month","id":"list-2"},{"message":"master","footer":"unlimited messsages/month","id":"list-3"}]},{"title":"all feature","list":[{"message":"super","footer":"10k messsages/month","id":"list-4"},{"message":"advanced","footer":"25k messsages/month","id":"list-5"},{"message":"ultra","footer":"unlimited messsages/month","id":"list-6"}]}]}'
),
  CURLOPT_HTTPHEADER => array(
    'Authorization: TOKEN'
  ),
));

$response = curl_exec($curl);
if (curl_errno($curl)) {
  $error_msg = curl_error($curl);
}
curl_close($curl);

if (isset($error_msg)) {
 echo $error_msg;
}
echo $response;

You can see on postman see example on how to send whatsapp message with API PHP

Available parameter

  • target (required) (string) - target number, separate with comma, support variable
  • message (optional) (string) - text message, support variable
  • url (optional) (string) - support image, file, audio, video, optional
  • filename (optional) (string) - custom filename, optional
  • schedule (optional) (int) - unix timestamp to send message on schedule
  • delay (optional) (string) - min 0, add - to random delay ex: 1-10 will produce random delay between 1 to 10 seconds, optional
  • countryCode (string) - replace first zero with country code, default 62, set 0 to disable replacement, optional
  • buttonJSON (string) (deprecated) - json format for sending button message, footer is optional, max 3 buttons, id is optional if the response is not needed, support image/video combined with url field
  • templateJSON (string) (deprecated) - json format for sending template message, footer is optional, support call/url/normal button, id is optional if the response is not needed, text only, does not work on iphone yet
  • listJSON (string) (deprecated) - json format for sending list message, footer is optional, title is optional, buttons->title is optional, list->footer is optional, id is optional if the response is not needed, text only
  • location (optional) (string) - format : latitude,longitude
  • typing (optional) (bool) : typing indicator, default : false
  • choices (optional) (string) : poll choices, minimum 2, maximum 12, separate with comma
  • select (optional) (string) : poll select limitation, single or multiple
  • pollname (optional) (string) : poll name
  • file (optional) (binary) : upload file directly from local/form

TOKEN must be filled by your own token. See how to get token.

TOKEN can be multiple, separate with comma, ex: xxxxxx,yyyyyy.

Multiple TOKEN will work as rotator, every target will be sent by random device based on listed token.

Multiple TOKEN can only be used under an account.

You cannot list multiple TOKEN where the device is not belong to the same account

Sending multiple numbers can be done by adding comma. ex: 6282xxxxxx,6285xxxxxxxx,6283xxxxxxxxx.

Sending variable supported on API.

Filename only works on file and audio type.

Consider the file limitation rules when sending an attachment.

Response

successfull run response example

{
    "detail": "success! message in queue",
    "id": [
        "15362"
    ],
    "process": "processing",
    "status": true,
    "target": [
        "6282227097005"
    ]
}

There are 3 detail on successfull run API

  1. Success! message in queue : will be processed immediately
  2. Success! message will be sent on scheduled time : will be processed on scheduled time
  3. Success! message pending due to server issue, will be sent later : there is something wrong with the server, but your message will be sent shortly after the server run again.

On 3rd detail, it may happen if server is restarting, server is not responding, server is down, trouble on the network and so on.

It's not your fault, but ours.

Again, your message is saved and will be sent shortly after the server run again.

Failed run response always return status : false

- Invalid token : if the token is invalid

{
    "Status": false,
    "reason": "token invalid"
}

- Devices must belong to an account : you cannot list token under different account

{
    "Status": false,
    "reason": "devices must belong to an account"
}

- Input invalid : if any of the value is invalid

{
    "reason": "input invalid",
    "status": false
}

- Url invalid : if url provided invalid

{
    "reason": "url invalid",
    "status": false
}

- Url unreachable : if url not responding

{
    "reason": "url unreachable",
    "status": false
}

- File format not supported : use supported format

{
    "reason": "file format not supported",
    "status": false
}

- File size must under 4MB : file cannot exceed 4MB

{
    "reason": "file size must under 4MB",
    "status": false
}

- Target invalid : target is not a valid number

{
    "reason": "target invalid",
    "status": false
}

- JSON format invalid : invalid JSON format, check your json format

{
    "reason": "JSON format invalid",
    "status": false
}

- Insufficient quota : requested message count > remaining quota. The message(s) will not be saved

{
    "reason": "insufficient quota",
    "status": false
}

Related knowledge

See more
Made with in Indonesia