### Successful Response Example
Source: https://docs.fonnte.com/api-get-devices
This is an example of a successful response when retrieving device information. It details connected devices, total devices, and other account-specific metrics.
```json
{
"connected": 0,
"data": [
{
"autoread": "off",
"device": "6287866250310",
"expired": "1707782400",
"name": "tutorial",
"package": "Free",
"quota": "1000",
"status": "disconnect",
"token": "sUqjkKH+UG+@3SmnKrhz"
}
],
"devices": 1,
"messages": 0,
"status": true,
"type": "device"
}
```
--------------------------------
### Send Sequential Messages
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example demonstrates how to send messages in a specific sequence, where the order matters.
```APIDOC
## Send Sequential Messages
### Description
Send messages in a sequence, ensuring the order of delivery.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **data** (array) - Required - An array of message objects, each with 'target', 'message', and optional 'delay' and 'url'.
- **sequence** (boolean) - Required - Set to `true` to enable sequential sending.
### Request Example
```json
{
"data": [
{"target": "082227097005", "message": "1", "delay" : "0"},
{"target": "082227097005", "message": "2", "delay" : "0"},
{"target": "082227097005", "message": "3", "delay" : "0", "url":"https://fonnte.com/wp-content/uploads/2023/03/Logo-Fonnte-1536x368.png"},
{"target": "082227097005", "message": "4", "delay" : "0"},
{"target": "082227097005", "message": "5", "delay" : "0"}
],
"sequence": true
}
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the messages were sent successfully.
- **message** (string) - A message indicating the result of the operation.
```
--------------------------------
### Successful Response Example
Source: https://docs.fonnte.com/api-check-message-status
This is an example of a successful response when checking a message status.
```json
{
"id": 2,
"message_status": "sent",
"status": true
}
```
--------------------------------
### QR Code Response Example
Source: https://docs.fonnte.com/api-get-qr
This is an example of a successful response when generating a QR code. The 'url' field contains the base64 encoded image data.
```json
{
"status": true,
"url": "iVBORw0KGgoAAAANSUhEUgAAARQAAAEUCAYAA..."
}
```
--------------------------------
### Device Already Connected Response Example
Source: https://docs.fonnte.com/api-get-qr
This response indicates that the device is already connected to Fonnte.
```json
{
"reason": "device already connect",
"status": false
}
```
--------------------------------
### Send Message with File from Database
Source: https://docs.fonnte.com/how-to-send-whatsapp-message-with-php-api
This example demonstrates sending a WhatsApp message with a file retrieved from a database using PHP.
```APIDOC
## POST /send
### Description
Send a WhatsApp message with a file stored in a database.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's WhatsApp number.
- **message** (string) - Required - The text message content.
- **file** (CURLFile) - Required - The file to send, obtained from the database.
- **filename** (string) - Optional - The desired filename for the attached file (works for files and audio).
- **countryCode** (string) - Optional - The recipient's country code (e.g., '62' for Indonesia).
### Request Example
```php
'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 => $data,
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Error:' . curl_error($curl);
}
curl_close($curl);
echo $response; //log response fonnte
}
//get user data from database
$res = mysqli_query($db, "SELECT * FROM user WHERE id = 1");
$row = mysqli_fetch_assoc($res);
$data = [
"target" => $row["whatsapp"],
"message" => "Halo " . $row["name"] . ", berikut sertifikat kamu ya",
// "url" => $row["url"],
"file" => new CURLFile($url, "", $filename)
];
// send message
Kirimfonnte($token, $data);
?>
Form
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the request was successful.
- **message** (string) - A message describing the result of the operation.
```
--------------------------------
### Send Message with Local File
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example shows how to send a WhatsApp message with a local file attached. Ensure the file path is correct.
```APIDOC
## POST /send
### Description
Send a WhatsApp message with a local file attached.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's WhatsApp number.
- **message** (string) - Required - The content of the message.
- **file** (file) - Required - The local file to send (e.g., 'localfile.png').
- **filename** (string) - Optional - The filename for the attached media.
- **countryCode** (string) - Optional - The recipient's country code.
### Request Example
```json
{
"target": "08123456789",
"message": "test message",
"file": "new CURLFile(\"localfile.png\")",
"filename": "my-file.pdf",
"countryCode": "62"
}
```
### Headers
- **Authorization** (string) - Required - Your API token (e.g., 'TOKEN').
```
--------------------------------
### Failed to Get Whatsapp Group Response Example
Source: https://docs.fonnte.com/api-get-whatsapp-group-list
This response signifies an issue with retrieving the WhatsApp group data. It suggests a problem with the group data itself.
```json
{
"detail": "failed to get whatsapp group",
"status": false
}
```
--------------------------------
### Send Message with PHP and MySQL Integration
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example shows a proof-of-concept for sending WhatsApp messages by integrating Fonnte API with PHP and MySQL, including sending files from a database or form.
```APIDOC
## POST /send
### Description
Send a WhatsApp message using Fonnte API, integrated with PHP and MySQL. This function can send messages with files retrieved from a database or uploaded via a form.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body (for `Kirimfonnte` function)
- **token** (string) - Required - Your API token.
- **data** (array) - Required - An array containing message details:
- **target** (string) - Required - The recipient's WhatsApp number.
- **message** (string) - Required - The content of the message.
- **file** (file) - Optional - The file to send, can be a local path or from `$_FILES`.
- **filename** (string) - Optional - The filename for the attached media.
- **countryCode** (string) - Optional - The recipient's country code.
### Request Example (within `Kirimfonnte` function)
```json
{
"target": "recipient_whatsapp_number",
"message": "Hello, here is your certificate.",
"file": "new CURLFile(\"files/Sertifikat.pdf\", \"\", \"Sertifikat1.pdf\")"
}
```
### Headers
- **Authorization** (string) - Required - Your API token.
```
--------------------------------
### Get Devices
Source: https://docs.fonnte.com/api-get-devices
This endpoint retrieves a list of all devices registered to your account. It requires your account token for authentication.
```APIDOC
## POST https://api.fonnte.com/get-devices
### Description
Retrieves a list of all devices registered to your account.
### Method
POST
### Endpoint
https://api.fonnte.com/get-devices
### Parameters
#### Headers
- **Authorization** (string) - Required - Your account token. Example: `TOKEN`
### Request Example
```json
{
"example": "request body"
}
```
### Response
#### Success Response (200)
- **connected** (integer) - The number of connected devices.
- **data** (array) - An array of device objects.
- **autoread** (string) - Autoread status ('on' or 'off').
- **device** (string) - The device number.
- **expired** (string) - Device expiration Unix timestamp.
- **name** (string) - The name of the device.
- **package** (string) - The device package type.
- **quota** (string) - The device's message sending quota.
- **status** (string) - The device status ('connect' or 'disconnect').
- **token** (string) - The device token.
- **devices** (integer) - The total number of devices in the account.
- **messages** (integer) - The total number of messages requested in the account.
- **status** (boolean) - Indicates if the request was successful.
- **type** (string) - The account type.
#### Response Example
```json
{
"connected": 0,
"data": [
{
"autoread": "off",
"device": "6287866250310",
"expired": "1707782400",
"name": "tutorial",
"package": "Free",
"quota": "1000",
"status": "disconnect",
"token": "sUqjkKH+UG+@3SmnKrhz"
}
],
"devices": 1,
"messages": 0,
"status": true,
"type": "device"
}
```
#### Error Response (400)
- **reason** (string) - Describes the error, e.g., "unknown user".
- **status** (boolean) - Indicates if the request was successful (false in case of error).
#### Error Response Example
```json
{
"reason": "unknown user",
"status": false
}
```
```
--------------------------------
### Get All Devices Information (PHP)
Source: https://docs.fonnte.com/api-get-devices
Use this PHP cURL request to fetch all device information linked to your account. Ensure you replace 'TOKEN' with your actual account token.
```php
'https://api.fonnte.com/get-devices',
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_HTTPHEADER => array(
'Authorization: TOKEN'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
```
--------------------------------
### API Get QR
Source: https://docs.fonnte.com/category/api
This API allows for scanning devices outside of Fonnte by generating a QR code.
```APIDOC
## API Get QR
### Description
This API makes scanning a device outside of Fonnte possible.
### Method
GET
### Endpoint
/api/get-qr
```
--------------------------------
### Send Poll Message
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example shows how to send a WhatsApp poll message to individuals or groups.
```APIDOC
## Send Poll Message
### Description
Send a WhatsApp poll message.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's phone number or group ID.
- **message** (string) - Required - The main message content.
- **choices** (string) - Required - Comma-separated list of poll choices.
- **select** (string) - Required - Type of poll ('single' or 'multiple').
- **pollname** (string) - Required - The name of the poll.
### Request Example
```json
{
"target": "082227097005",
"message": "test dari postman",
"choices": "satu,dua,tiga",
"select": "single",
"pollname": "pollku"
}
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the poll was sent successfully.
- **message** (string) - A message indicating the result of the operation.
```
--------------------------------
### Base URL for Sending Messages via GET
Source: https://docs.fonnte.com/api-send-message-by-url-get
This is the base URL structure for sending messages using the GET method. Append query parameters to this URL to specify message details.
```url
https://api.fonnte.com/send/?_queries_
```
--------------------------------
### Send File from Database using PHP and MySQL
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This comprehensive example demonstrates sending a file (e.g., a certificate PDF) from a database to a WhatsApp number using PHP. It includes database connection, file handling, and a reusable function for sending messages via the Fonnte API.
```php
'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 => $data,
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Error:' . curl_error($curl);
}
curl_close($curl);
echo $response; //log response fonnte
}
//get user data from database
$res = mysqli_query($db, "SELECT * FROM user WHERE id = 1");
$row = mysqli_fetch_assoc($res);
$data = [
"target" => $row["whatsapp"],
"message" => "Halo " . $row["name"] . ", berikut sertifikat kamu ya",
// "url" => $row["url"],
"file" => new CURLFile($url, "", $filename)
];
// send message
Kirimfonnte($token, $data);
?>
Form
```
--------------------------------
### Send Message with Image via URL
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example demonstrates how to send a WhatsApp message with an image attached, using a URL for the image.
```APIDOC
## POST /send
### Description
Send a WhatsApp message with an image attached via a URL.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's WhatsApp number.
- **message** (string) - Required - The content of the message.
- **url** (string) - Required - The URL of the image to send.
- **filename** (string) - Optional - The filename for the attached media.
- **countryCode** (string) - Optional - The recipient's country code.
### Request Example
```json
{
"target": "08123456789",
"message": "test message",
"url": "https://md.fonnte.com/images/logo-dashboard.png",
"filename": "my-file.pdf",
"countryCode": "62"
}
```
### Headers
- **Authorization** (string) - Required - Your API token (e.g., 'TOKEN').
```
--------------------------------
### Send Message from Form Upload
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example demonstrates sending a WhatsApp message with a file uploaded directly from an HTML form.
```APIDOC
## POST /send
### Description
Send a WhatsApp message with a file uploaded directly from an HTML form.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's WhatsApp number.
- **message** (string) - Required - The content of the message.
- **file** (file) - Required - The file uploaded from the form (e.g., from `$_FILES["file"]["tmp_name"]`).
- **filename** (string) - Optional - The filename for the attached media.
- **countryCode** (string) - Optional - The recipient's country code.
### Request Example
```json
{
"target": "08123456789",
"message": "test message",
"file": "new CURLFile($file, '', $name)",
"filename": "my-file.pdf",
"countryCode": "62"
}
```
### Headers
- **Authorization** (string) - Required - Your API token (e.g., 'TOKEN').
```
--------------------------------
### Send Scheduled Message from Database with PHP
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example demonstrates sending a scheduled WhatsApp message by fetching user data from a MySQL database. It includes a function to handle the API request and dynamically sets the schedule time based on database entries.
```php
'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' => $data['target'],
'message' => $data['message'],
'schedule' => $data['schedule'],
),
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; //log response fonnte
}
//get user data from database
$res = mysqli_query($db, "SELECT * FROM user");
$row = mysqli_fetch_assoc($res);
$schedule = strtotime($row["schedule"] . $row["timezone"]);
$data = [
"target" => $row["whatsapp"],
"message" => "Halo " . $row["name"] . ", jangan lupa untuk mengikuti webinar hari ini ya",
"schedule" => $schedule,
];
// send message
Kirimfonnte($token, $data);
?>
```
--------------------------------
### Get Device Information using PHP
Source: https://docs.fonnte.com/api-device-profile
Use this PHP cURL request to fetch your device's profile information. Ensure your 'Authorization: TOKEN' header is correctly set with your valid token.
```php
'https://api.fonnte.com/device',
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_HTTPHEADER => array(
'Authorization: TOKEN'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
```
--------------------------------
### Add Device
Source: https://docs.fonnte.com/api-add-device
This snippet demonstrates how to add a new device using the fonnte API. It includes details on required and optional parameters, as well as example request and response formats.
```APIDOC
## POST https://api.fonnte.com/add-device
### Description
This endpoint allows you to add a new device to your fonnte account programmatically. You can configure various settings for the device, such as its name, number, and chat features.
### Method
POST
### Endpoint
https://api.fonnte.com/add-device
### Parameters
#### Request Body
- **name** (string) - Required - The name of the device. Minimum 2 and maximum 30 characters.
- **device** (string) - Required - The device number. Must be unique across all users, with a minimum of 8 and maximum of 15 digits.
- **autoread** (boolean) - Optional - Activate the autoread chat feature.
- **personal** (boolean) - Optional - Enable autoread for personal chats.
- **group** (boolean) - Optional - Enable autoread for group chats.
### Request Example
```json
{
"name": "device name",
"device": "08123456789",
"autoread": "false",
"personal": "false",
"group": "false"
}
```
### Response
#### Success Response (200)
On successful device creation, you receive basic device information including a token.
- **autoread** (string) - The autoread status ('on' or 'off').
- **device** (string) - The device number.
- **group** (string) - The group chat autoread status ('on' or 'off').
- **name** (string) - The name of the device.
- **personal** (string) - The personal chat autoread status ('on' or 'off').
- **status** (boolean) - Indicates if the operation was successful.
- **token** (string) - The token associated with the newly created device.
#### Response Example
```json
{
"autoread": "off",
"device": "08123456789",
"group": "off",
"name": "device name",
"personal": "off",
"status": true,
"token": "M@N!4Yr-Vs#CPtaopCkE"
}
```
#### Error Responses
- **Input Invalid**: Indicates an issue with the provided data.
```json
{
"reason": "input invalid",
"status": false
}
```
- **Unknown User**: Indicates an invalid or empty account token.
```json
{
"reason": "unknown user",
"status": false
}
```
- **Too Much Free Device**: Indicates that the account has reached the limit of 10 free devices.
```json
{
"reason": "too much free device",
"status": false
}
```
- **Device Already Exist**: Indicates that the provided device number already exists.
```json
{
"reason": "device already exist",
"status": false
}
```
```
--------------------------------
### Send Location Message
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example demonstrates how to send a WhatsApp message with location data using latitude and longitude.
```APIDOC
## Send Location Message
### Description
Send a WhatsApp message with location data.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's phone number.
- **location** (string) - Required - The location in "latitude,longitude" format.
### Request Example
```json
{
"target": "08123456789",
"location": "-7.983908, 112.621391"
}
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the message was sent successfully.
- **message** (string) - A message indicating the result of the operation.
```
--------------------------------
### Send Message via Form Upload
Source: https://docs.fonnte.com/how-to-send-whatsapp-message-with-php-api
This example shows how to send a WhatsApp message with a file directly from a form upload, without needing to save it locally first.
```APIDOC
## POST /send
### Description
Send a WhatsApp message with a file directly from a form upload.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's WhatsApp number.
- **message** (string) - Required - The text message content.
- **file** (CURLFile) - Required - The file uploaded via form data. Use `$_FILES["your_input_name"]["tmp_name"]`.
- **filename** (string) - Optional - The desired filename for the attached file (works for files and audio).
- **countryCode** (string) - Optional - The recipient's country code (e.g., '62' for Indonesia).
### Request Example
```php
'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',
'message' => 'test message',
'file' => new CURLFile($file, '', $name),
'filename' => 'my-file.pdf', //optional, only works on file and audio
'countryCode' => '62', //optional
),
CURLOPT_HTTPHEADER => array(
'Authorization: TOKEN' //change TOKEN to your actual token
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the request was successful.
- **message** (string) - A message describing the result of the operation.
```
--------------------------------
### Successful Device Profile Response
Source: https://docs.fonnte.com/api-device-profile
This is an example of a successful response when retrieving device profile information. It includes details like device status, expiration, and message quota.
```json
{
"device": "6282227097005",
"device_status": "connect",
"expired": "18 November 2029",
"messages": 16785,
"name": "Fonnte admin",
"package": "Reguler",
"quota": "78",
"status": true
}
```
--------------------------------
### Send WhatsApp Messages from PHP with MySQL Integration
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example demonstrates sending personalized WhatsApp messages to users fetched from a MySQL database. It defines a function to handle Fonnte API requests and loops through database records to send messages with customizable delays. Ensure your 'koneksi.php' file correctly establishes the database connection and that the 'user' table has 'whatsapp' and 'name' columns.
```php
'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(
'data' => $data['data'],
),
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; //log response fonnte
}
//ambil data user dari database
$res = mysqli_query($db, "SELECT * FROM user");
//looping data user
$alldata = [];
while ($row = mysqli_fetch_assoc($res)) {
$data = [
"target" => $row["whatsapp"],
"message" => "Halo " . $row["name"] . ", Terimakasih telah mendaftar di aplikasi kami",
"delay" => "1-3", //add delay to control sending message speed
];
array_push($alldata, $data);
}
//request data
$data = [
"data" => json_encode($alldata), //transform array to json (string)
];
//send message
Kirimfonnte($token, $data);
```
--------------------------------
### Send Scheduled WhatsApp Message from Database with PHP
Source: https://docs.fonnte.com/how-to-send-whatsapp-message-with-php-api
This example demonstrates sending a scheduled WhatsApp message by fetching user data and schedule times from a MySQL database. It includes a function to handle the API request and processes data from the 'user' table.
```php
'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' => $data['target'],
'message' => $data['message'],
'schedule' => $data['schedule'],
),
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; //log response fonnte
}
//get user data from database
$res = mysqli_query($db, "SELECT * FROM user");
$row = mysqli_fetch_assoc($res);
$schedule = strtotime($row["schedule"] . $row["timezone"]);
$data = [
"target" => $row["whatsapp"],
"message" => "Halo " . $row["name"] . ", jangan lupa untuk mengikuti webinar hari ini ya",
"schedule" => $schedule,
];
// send message
Kirimfonnte($token, $data);
```
--------------------------------
### Send File from Form Upload using PHP
Source: https://docs.fonnte.com/send-whatsapp-message-with-php-api
This example shows how to send a file directly from a form upload using PHP and the Fonnte API. This method avoids the need to save the file locally first.
```php
'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',
'message' => 'test message',
'file' => new CURLFile($file, '', $name),
'filename' => 'my-file.pdf', //optional, only works on file and audio
'countryCode' => '62', //optional
),
CURLOPT_HTTPHEADER => array(
'Authorization: TOKEN' //change TOKEN to your actual token
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
```
--------------------------------
### Send WhatsApp Messages from Database using PHP and Fonnte API
Source: https://docs.fonnte.com/how-to-send-whatsapp-message-with-php-api
This example demonstrates sending personalized WhatsApp messages to users stored in a MySQL database. It includes a function to handle the API request and loops through database records to send messages with delays.
```php
'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(
'data' => $data['data'],
),
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; //log response fonnte
}
//ambil data user dari database
$res = mysqli_query($db, "SELECT * FROM user");
//looping data user
$alldata = [];
while ($row = mysqli_fetch_assoc($res)) {
$data = [
"target" => $row["whatsapp"],
"message" => "Halo " . $row["name"] . ", Terimakasih telah mendaftar di aplikasi kami",
"delay" => "1-3", //add delay to control sending message speed
];
array_push($alldata, $data);
}
//request data
$data = [
"data" => json_encode($alldata), //transform array to json (string)
];
//send message
Kirimfonnte($token, $data);
?>
```
--------------------------------
### Send Message using JavaScript Fetch API
Source: https://docs.fonnte.com/api-send-message-with-javascript
This snippet demonstrates how to construct and send a message using the Fonnte API with JavaScript's fetch function. It includes examples of appending various data types to a FormData object, setting headers, and handling the response.
```APIDOC
## POST https://api.fonnte.com/send
### Description
Sends a message through the Fonnte API.
### Method
POST
### Endpoint
https://api.fonnte.com/send
### Parameters
#### Request Body
- **target** (string) - Required - The recipient's phone number.
- **message** (string) - Required - The content of the message.
- **url** (string) - Optional - URL for sending media.
- **filename** (string) - Optional - Filename for the attached media.
- **schedule** (string) - Optional - Schedule time for the message (e.g., "0" for immediate).
- **delay** (string) - Optional - Delay in seconds before sending.
- **countryCode** (string) - Optional - Country code for the target number.
- **buttonJSON** (string) - Optional - JSON string for interactive buttons.
- **templateJSON** (string) - Optional - JSON string for message templates.
- **listJSON** (string) - Optional - JSON string for list messages.
### Request Example
```javascript
const data = new FormData();
data.append("target", "082227097005");
data.append("message", "kirim dari js");
data.append("url", "https://md.fonnte.com/images/wa-logo.png");
data.append("filename", "filename.pdf");
data.append("schedule", "0");
data.append("delay", "2");
data.append("countryCode", "62");
data.append("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"}]}');
data.append("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"}]}');
data.append("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"}]}]}');
const response = await fetch("https://api.fonnte.com/send", {
method: "POST",
mode: "cors",
headers: new Headers({
Authorization: "TOKEN",
}),
body: data,
});
const res = await response.json();
console.log(res);
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the request was successful.
- **message** (string) - A message describing the result of the operation.
- **data** (object) - Contains additional data related to the response, if any.
```
--------------------------------
### PHP Webhook Implementation
Source: https://docs.fonnte.com/webhook-get-submission
This PHP script demonstrates how to receive and process submission data sent to your webhook. It decodes the JSON payload, extracts relevant information, and shows an example of sending a reply using the Fonnte API.
```APIDOC
## Webhook Get Submission
This endpoint receives submission data when a client submits their information. You can process this data and integrate it into your system.
### Available Parameters
- **Submission** (string) - The name of the submission.
- **Sender** (string) - The sender's WhatsApp number.
- **Name** (string) - The name of the sender.
- **List** (object) - The submission data, typically a key-value pair object.
### Example Usage (PHP)
```php
"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' => $target,
'message' => $data["message"],
),
CURLOPT_HTTPHEADER => array(
"Authorization: TOKEN" // Replace TOKEN with your actual API token
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
// Example of processing and replying
$reply = [
"message" => $json // Echoing the received JSON as a message for demonstration
];
sendFonnte("YOUR_PHONE_NUMBER", $reply); // Replace YOUR_PHONE_NUMBER with the target recipient's number
?>
```
**Note:** Replace `TOKEN` with your actual Fonnte API token and `YOUR_PHONE_NUMBER` with the desired recipient's phone number.
```
--------------------------------
### No Whatsapp Group Yet Response Example
Source: https://docs.fonnte.com/api-get-whatsapp-group-list
This response is returned if you have not yet updated your WhatsApp group list via the API or if you are not a member of any groups. Call the 'update whatsapp group list' API first.
```json
{
"detail": "you have no whatsapp group yet",
"status": false
}
```
--------------------------------
### Successful Device Creation Response
Source: https://docs.fonnte.com/api-add-device
This is a sample successful response when a device is added. It includes basic information about the created device and a status of true.
```json
{
"autoread": "off",
"device": "08123456789",
"group": "off",
"name": "device name",
"personal": "off",
"status": true,
"token": "M@N!4Yr-Vs#CPtaopCkE"
}
```
--------------------------------
### API send message by url (GET)
Source: https://docs.fonnte.com/category/api
Send a message using a GET request via a URL.
```APIDOC
## API send message by url (GET)
### Description
API send message get method.
### Method
GET
### Endpoint
/api/send-message-by-url
```
--------------------------------
### Send Message via GET Request
Source: https://docs.fonnte.com/api-send-message-by-url-get
This API allows sending messages using a GET request. It is strongly advised not to use this in frontend applications as it exposes sensitive tokens. Use this method only if your environment does not support POST requests.
```APIDOC
## GET https://api.fonnte.com/send/
### Description
Sends a message using a GET request. This method is not recommended for frontend use due to security implications and should only be used when the POST method is not feasible.
### Method
GET
### Endpoint
https://api.fonnte.com/send/
### Parameters
#### Query Parameters
- **token** (string) - Required - Your device's token. Separate multiple tokens with a comma.
- **target** (string) - Required - Target phone number(s). Separate multiple numbers with a comma. Supports variables.
- **message** (string) - Optional - The text message content. Supports variables.
- **url** (string) - Optional - URL for media (image, file, audio, video). Note: File parameter is not available in this method; use 'url' for all media.
- **filename** (string) - Optional - Custom filename for the attached media.
- **schedule** (int) - Optional - Unix timestamp for scheduled message delivery.
- **delay** (string) - Optional - Delay in seconds. Format: 'min-max' for random delay (e.g., '1-10').
- **countryCode** (string) - Optional - Country code to prepend to the target number. Default is '62'. Set to '0' to disable replacement.
- **location** (string) - Optional - Location in 'latitude,longitude' format.
- **typing** (bool) - Optional - Enable typing indicator. Defaults to false.
- **redirect** (string) - Optional - URL to redirect to after the process completes.
- **choices** (string) - Optional - Poll choices, separated by commas. Minimum 2, maximum 12.
- **select** (string) - Optional - Poll selection type: 'single' or 'multiple'.
- **pollname** (string) - Optional - Name of the poll.
### Request Example
```
https://api.fonnte.com/send/?token=YOUR_TOKEN&target=TARGET_NUMBER&message=Hello%20World
```
### Response
All responses will follow the response format of the POST method for sending messages.
```
--------------------------------
### API Get Whatsapp Group List
Source: https://docs.fonnte.com/category/api
Retrieve a list of all WhatsApp groups associated with your device.
```APIDOC
## API Get Whatsapp Group List
### Description
Get a list of your device's whatsapp group.
### Method
GET
### Endpoint
/api/get-whatsapp-group-list
```
--------------------------------
### Order Package via API (PHP)
Source: https://docs.fonnte.com/api-order
Use this PHP cURL request to order a package. Ensure you replace 'TOKEN' with your actual authorization token and adjust the 'plan', 'duration', 'duration-value', 'ai-quota', and 'ai-data' parameters as needed.
```php
'https://api.fonnte.com/order',
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('plan' => 1,'duration' => 1,'duration-value' => 1,'ai-quota' => 500,'ai-data' => 0),
CURLOPT_HTTPHEADER => array(
'Authorization: TOKEN'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
```