To connect the ChatApp API, you will need to perform a few simple steps. Let's consider everything in stages:
Step 1. Registration in your personal account
Detailed description of the registration process
Step 2. Buying or requesting a demo license
Detailed description of the process of purchasing a demo license
Step 3. Create an appId in your account
To create an appId go to its creation page
Step 4. Get Access Tokens
Consider an example of executing a request to obtain access tokens using the v1.tokens.make method.
Note: All request execution examples are in PHP using the Guzzle http-client.
$client = new \GuzzleHttp\Client();
try {
$response = $client->post(
'https://api.chatapp.online/v1/tokens',
[
'headers' => [
'Content-Type' => 'application/json',
],
'json' => [
'email' => 'test@test.test', // email from personal account
'password' => '123456', // password from personal account
'appId' => 'app_4556_1', // appId from personal account
],
]
);
$body = $response->getBody();
echo '<pre>';
print_r(json_decode((string)$body));
} catch (\Exception $e) {
echo '<pre>';
print_r([$e->getCode(), $e->getMessage()]);
}
In response to the request, you will receive two tokens: refreshToken and accessToken. However, you only need one of them, the accessToken, to make subsequent requests.
Step 5. Sending a message
Let's use the example of sending a text message using the v1.messages.send.text method:
$client = new \GuzzleHttp\Client();
$licenseId = 12345;
$messengerType = 'grWhatsApp';
$chatId = '70000000000'; // phone or chatId
$accessToken = '$2y$10$loFiiY4XsYIDv5lfuJ9qROnpfxe000fsvjR/F1qWYiTgJEXaDiMfa';
try {
$response = $client->post(
"https://api.chatapp.online/v1/licenses/$licenseId/messengers/$messengerType/chats/$chatId/messages/text",
[
'headers' => [
'Authorization' => $accessToken,
],
'json' => [
'text' => 'Hello world!',
],
]
);
$body = $response->getBody();
echo '<pre>';
print_r(json_decode((string)$body));
} catch (\Exception $e) {
echo '<pre>';
print_r([$e->getCode(), $e->getMessage()]);
}