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/token'; //Forming the URL for the request 

/** We collect data for the request  */

$data = [

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

'password' => '1298um230er98w',

'type' => 'direct',

];

$ch = curl_init($url);

// 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';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

curl_setopt($url_to, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // this index comes in response to all requests where access_token and refresh_token are required once a day to update these tokens

$data = $response['data']; // this index comes in response in all requests

$instances = $data['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';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // this index comes in response to all requests where access_token and refresh_token are required once a day to update these tokens

$data = $response['data']; // this index comes in response in all requests

$instances = $data['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 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);

$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 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);

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

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

GET - Request for a list of dialogs (getDialogs)

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

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

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

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

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

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

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init();

curl_setopt($link, CURLOPT_HTTPHEADER,

    array(

        "Authentication: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

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

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

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

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';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

$instances = $data['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'; //Forming the URL for the request

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

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

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

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

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

$access_token = '2y$10qeCKubxGyPanuONchMMUe7MiQos6GcLXFk8gmmUfLzwPobQTP1C';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

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

$lastMessageNumber = $data['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';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_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);

$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

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

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';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

/** We collect data for the request */

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER,

    array(

        "Authorization: {$access_token}",

        "Refresh: {$refresh_token}"

    )

);

// отправка PUT запроса.

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);

$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

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

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';

$refresh_token = '2y$$2y$10x8UgIewq3ckLrQi79z/A7OuwobUOw3jTyQ7lqzIt6R0gbVl';

$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"

* }

*

* 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);

$$tokens =  $response['tokens']; // This index comes in response to all requests where access_token and refresh_token are piped once a day to update these tokens

$data = $response['data']; // This index comes in response in all requests

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