‘ba8a97ab-402a-4b4b-a65d-0c5313f44cb7’, ‘client_secret’ => ‘LwURQKDKobjH56epxd7l7SaL0YMHLHcA8wVbuzc0bl18MstX13A6UIlo9h5Z8xuB’, ‘grant_type’ => ‘authorization_code’, ‘code’ => ‘def50200a61fe982718b11b91324dabe6585a74c9bd67bc0484b68cc846af50f2de8dbf57e593374cc9c7441d7a6f97047630760709b3271386df432746281899905145d3b5186f7d8890a1ed05ffd6f631e3949584f57a54d1da4d2886dd491a6fa441bd3c1b163cabfc0c2b2fbe11931620116f656929a16d2acb625a824acc17c1d9337c6accd70f7b541bc481b55d839d58455c4b5a22e1cf8b89c6f90c91cf8ca402fb8b538d2487a8aa554a13ff12412b4ee07b0498de27d36497c04b96037d4fbab96933c4202644eb62a2a646b46b1645342cf379c10df4c013fec5119521db3bcf8cbd1cf087abafe4817d11c83e0eb9f7bfd484343f71774a861523a7632a4eae8957f8175a3e0fe18e968835c1f1df2d3dde1b0388281184aea5e43b88301c2d47204d4d73c3b98ae770eadbad54fbee2e578a67691e3cc87b218d0a85289b810994e5d70594bd7469b3c88ae508c8516af034d29ee1bb0dd7404f941e410bbd880b43928259a41a532161f3fc2f190a8339abc74af4e8b63f8ab4dd44cff6026f6adff36df8776749818a959b4c60cb699209a0c8817aceeecb107a23e250e288470eae10edddda41599682af3299c1d1bc5f36c62f14d5dba66063214c4c1c58f94b376d7841ef8f4d379e8b3cdf2c42eb392fe83e3b6974afe421025d865b8761c228a2b3a72843eaf262e’, ‘redirect_uri’ => ‘https://taurosfit.com/api-kommo/’, ]; /** * We need to initiate a request to the server. * Let’s use library with cURL. * You can also use cross-platform cURL, if you don’t code on PHP. */ $curl = curl_init(); //Saving descriptor cURL /** Installing required options for session cURL */ curl_setopt($curl,CURLOPT_RETURNTRANSFER, true); curl_setopt($curl,CURLOPT_USERAGENT,’amo-oAuth-client/1.0′); curl_setopt($curl,CURLOPT_URL, $link); curl_setopt($curl,CURLOPT_HTTPHEADER,[‘Content-Type:application/json’]); curl_setopt($curl,CURLOPT_HEADER, false); curl_setopt($curl,CURLOPT_CUSTOMREQUEST, ‘POST’); curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, 2); $out = curl_exec($curl); //Initiating request to API and saving response to variable $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); /** * Now we can process responses from the server. * It’s an example, you can process this data the way you want. */ $code = (int)$code; $errors = [ 400 => ‘Bad request’, 401 => ‘Unauthorized’, 403 => ‘Forbidden’, 404 => ‘Not found’, 500 => ‘Internal server error’, 502 => ‘Bad gateway’, 503 => ‘Service unavailable’, ]; try { /** If the response code is not successful – return an error message */ if ($code < 200 || $code > 204) { throw new Exception(isset($errors[$code]) ? $errors[$code] : ‘Undefined error’, $code); } } catch(\Exception $e) { die(‘Error: ‘ . $e->getMessage() . PHP_EOL . ‘Error code: ‘ . $e->getCode()); } /** * Data will be received in JSON, that’s why to get readable data, * we need to parse that data that PHP will understand */ $response = json_decode($out, true); $access_token = $response[‘access_token’]; //Access token $refresh_token = $response[‘refresh_token’]; //Refresh token $token_type = $response[‘token_type’]; //Token type $expires_in = $response[‘expires_in’]; //After how long does the token expire