Examples РНР for our API

From English wiki app24.online
Jump to navigation Jump to search


Integration via API - https://api.app24.online/docs/

Developers must create an APP ID for their applications

PUT - Request to get a token (getToken)

$link = 'https://api.app24.online/tokens'; //Формируем URL для запроса

/** We collect data for the request */

$data = [

'email' => 'myemail@mydomain.ru',

'password' => '1298um230er98w',

'app_id' => 'app_1234_1',

];

$ch = curl_init($url);

// sending a PUT request

curl_setopt_array($curl, array(

    CURLOPT_URL => $link.'?'.http_build_query($data),
    
    CURLOPT_RETURNTRANSFER => true,
    
    CURLOPT_CUSTOMREQUEST => 'PUT',
));

$response = curl_exec($ch);

curl_close($curl);

/**

* We receive data in JSON format, therefore, to get readable data ,

* we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$cabinet_user_id = $response['cabinet_user_id']; //User ID in the personal account 

$access_token = $response['access_token']; //Access token

$access_token_end_time = $response['access_token_end_time']; // Access token expiration

$refresh_token = $response['refresh_token']; //Refresh token

$refresh_token_end_time = $response['refresh_token_end_time']; // Refresh token expiration

# ---------------------------------------------------------------------------

PUT - Request to refresh access, refresh tokens (refreshToken)

$url_to = curl_init('https://api.app24.online/refresh-tokens/user/912/type/app_912_1');

$refresh_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

curl_setopt($url_to, CURLOPT_HTTPHEADER,

    array(

        "Refresh: {$refresh_token}",

    )

);

// sending a PUT request. 

curl_setopt($ch, CURLOPT_PUT, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

$response = curl_exec($ch);

curl_close($curl);

/**

* We receive data in JSON format, therefore, to get readable data,


* we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$cabinet_user_id = $response['cabinet_user_id']; //User ID in the personal account

$access_token = $response['access_token']; //Access token

$access_token_end_time = $response['access_token_end_time']; // Access token expiration

$refresh_token = $response['refresh_token']; //Refresh token

$refresh_token_end_time = $response['refresh_token_end_time']; // Refresh token expiration

# ---------------------------------------------------------------------------

GET - Request to check the validity of tokens (checkToken)

$url_to = curl_init('https://api.app24.online/me');

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

curl_setopt($url_to, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($url_to, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($url_to);

curl_close($curl);

/**

* We receive data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$cabinet_user_id = $response['cabinet_user_id']; //User ID in the personal account

$access_token = $response['access_token']; //Access token

$access_token_end_time = $response['access_token_end_time']; // Access token expiration

$refresh_token = $response['refresh_token']; //Refresh token

$refresh_token_end_time = $response['refresh_token_end_time']; // Refresh token expiration

# ---------------------------------------------------------------------------

GET - Request for a list of instances (clientInstances)

$link = 'https://api.app24.online/instances/912'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* We receive data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$instances = $response['instances'];

# ---------------------------------------------------------------------------

GET - Request to check the existence of a phone (checkPhone)

$link = 'https://api.app24.online/user/912/instance/123456/phone/79220000001'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**


* We receive data in JSON format, therefore, to get readable data,

* we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$instances = $response['status'];

# ---------------------------------------------------------------------------

PUT - Request to set the language of system messages (setLocale)

$link = 'https://api.app24.online/set-locale'; //Forming the URL for the request

/** We collect data for the request */

$data = [

'locale' => 'ru',

];

$ch = curl_init($link);

// sending a PUT request.

curl_setopt($ch, CURLOPT_PUT, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

$response = curl_exec($ch);

curl_close($curl);

/**

* We receive data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$locale = $response['locale']; // Installed language [en или ru]

# ---------------------------------------------------------------------------

GET - Request for clarification about the current language of system messages (getLocale)

$link = 'https://api.app24.online/get-locale'; //Forming the URL for the request

/** We collect data for the request */

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $link);

curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);

$response = curl_exec($curl);

curl_close($curl);

/**

* We receive data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$locale = $response['locale']; // Installed language [en или ru]

# ---------------------------------------------------------------------------

GET - Request for a list of dialogs (getDialogs)

$link = 'https://api.app24.online/user/912/dialogs/112233/limit/2/page/1'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**


* We receive data in JSON format, therefore, to get readable data,

* we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

$instances = $response['dialogs']; // Array with a dialogs of the current instance 

# ---------------------------------------------------------------------------

GET - Dialogue request (getDialog)

$link = 'https://api.app24.online/user/912/dialog/112233/79220000001@c.us'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "id": "79220000001@c.us",

*   "name": "+7 922 000-00-01",

*   "metadata": {

*      "isGroup": false,

*      "participants": [],

*      "admins": [],

*      "participantsInfo": [],

*      "groupInviteLink": null

*   },

*   "last_time": 1620746639,

*   "image": "https:\/\/pps.whatsapp.net\/v\/t61.2000-24\/1.jpg"

* }

* We receive data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that is understandable PHP

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

GET - Request to set the READED status for all unread messages of the current user (markNewMessagesAsRead)

$link = 'https://api.app24.online/user/912/instance/112233/reset-chat/79221111112@c.us/author/79220000001@c.us'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

$instances = $response['dialogs']; // Array with a dialogs of the current instance 
# ---------------------------------------------------------------------------

GET - Request to set the READED status for all unread messages of the selected contact (markNewMessagesAsRead)

$link = 'https://api.app24.online/user/912/instance/112233/reset-chat/79220000001@c.us/author/79221111112@c.us'; //Формируем URL для запроса

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

$instances = $response['dialogs']; // Array with a dialogs of the current instance

# ---------------------------------------------------------------------------

GET - Request to get a list of messages for a given conversation (getMessages)

$type = 'text'; # один из [text, file, image, ptt, link, location, contact, read, typing, record]

$link = "https://api.app24.online/user/912/instance/112233/messages/79220000002/{$type}"; //Формируем URL для запроса

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

// sending a PUT request

curl_setopt($curl, CURLOPT_PUT, true);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "sent": true,

*   "message": "Sent to 79220000001@c.us",

*   "id": "true_79220000001@c.us_3EB0A79D45C44643F165",

*   "queueNumber": 1089,

*   "status_chat": "existing"

* }

*

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

GET - Request to get a list of messages for a given dialog with pagination (getMessagesHistory)

$link = 'https://api.app24.online/user/912/instance/112233/messages/79220000002@c.us/page/1/count/3'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

$instances = $response['messages']; // Array with a messages of the current dialog

$lastMessageNumber = $response['lastMessageNumber']; // The number of the last message in the chat

# ---------------------------------------------------------------------------

PUT - Request to send a new message (sendMessages)

$type = 'text'; # один из [text, file, image, ptt, link, location, contact, read, typing, record]

$link = "https://api.app24.online/user/912/instance/112233/messages/79220000002/{$type}"; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

// sending a PUT request.

curl_setopt($curl, CURLOPT_PUT, true);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "sent": true,

*   "message": "Sent to 79220000001@c.us",

*   "id": "true_79220000001@c.us_3EB0A79D45C44643F165",

*   "queueNumber": 1089,

*   "status_chat": "existing"

* }

*

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

PUT - Request to set status READED for unread incoming messages (readMessages)

$link = 'https://api.app24.online/user/912/instance/112233/read/79220000002'; // Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

// sending a PUT request .

curl_setopt($curl, CURLOPT_PUT, true);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "read": true,

*   "message": null,

*   "chatId": "79220000002@c.us"

* }

*

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

DELETE - Request to delete a message (deleteMessages)

$link = 'https://api.app24.online/user/912/instance/112233/messages/79220000002/true_79220000002@c.us_3EB0A79D45C44643F165'; // Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",
        "Refresh: {$refresh_token}"
    )

);

curl_setopt($curl, CURLOPT_URL, $link);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "sent": true,

*   "message": "message deleted"

* }

*

* e get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

POST - Group creation request (addGroup)

$link = "https://api.app24.online/user/912/instance/112233/group"; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

$fields = array(

    'groupName' => 'Test 1',

    'phones' => array('79220000001', '79220000002'),

    'messageText' => 'Text'

);

// sending a POST request.

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($fields));

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "created": true,

*   "message": "ok",

*   "chatId": "1493046918@g.us-13216468942@c.us",

*   "groupInviteLink": "string"

* }

*

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

DELETE - Request to delete a group (deleteGroup)

$link = 'https://api.app24.online/user/912/instance/112233/group/1493046918@g.us-13216468942@c.us'; // Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}"

    )

);

// sending DELETE request.

curl_setopt($curl, CURLOPT_URL, $link);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*  "result": {

*    "message": "Group deleted"

*  }

* }

*

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

PUT - Request to add a member to a group (addGroupParticipant)

$link = 'https://api.app24.online/user/912/instance/112233/group/1493046918@g.us-13216468942@c.us/add-participant/79220000002'; // Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

// sending a PUT request.

curl_setopt($curl, CURLOPT_PUT, true);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "add": true,

*   "message": "Added to 1493046918@g.us",

*   "groupId": "1493046918@g.us-13216468942@c.us"

* }

*

* We get the data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP understands

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------

GET - Запрос на получение статуса инстанса (getInstanceStatus)

$link = 'https://api.app24.online/user/912/instance/122332/status/full/wakeup'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

/** We collect data for the request*/

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

    )

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/**

* {

*   "accountStatus": "authenticated",

*   "statusData": {

*   "title": "Don't turn off your phone",

*   "msg": "WhatsApp connects to your phone to sync messages. To reduce data traffic, connect your phone to Wi-Fi.",

*   "substatus": "normal",

*   "actions": {}

* }

* We receive data in JSON format, therefore, to get readable data, * we will have to translate the answer into a format that PHP can understand

*/

$response = json_decode($response, true);

# ---------------------------------------------------------------------------