V
V
ventacom2018-10-25 16:50:43
API
ventacom, 2018-10-25 16:50:43

How to get a token in Bitrix24?

Good afternoon!
Found the following code to get a token from Bitrix24

public function getAccessToken() {
 
$access_token = false;

/* Авторизуемся на портале */
 $this->curl_b24("https://{$this->bitrix24domen}/crm/configs/import/lead.php?LOGIN=". urlencode($this->bitrix24login) . "&PASSWORD=" . urlencode($this->bitrix24password));
            
$auth_url = $this->curl_b24("https://{$this->bitrix24domen}/oauth/authorize/?client_id=" . $this->client_id . "&response_type=code&redirect_uri=" . $this->url . "/system/library/bitrix24.php", true);
        
    if (preg_match("/\?(.*?)$/i", $auth_url, $arRes)) {
      parse_str($arRes[1]);
      if (isset($code) && $code != "") {
        $res = json_decode($this->curl_b24("https://oauth.bitrix.info/oauth/token/?grant_type=authorization_code&client_id={$this->client_id}&client_secret={$this->client_secret}&code={$code}"));
        if ($res->access_token != "") {
          $access_token = $res->access_token;
          
          return $access_token;
        } else {
          $this->getAccessToken();
        }
      } 
    }
}

But with this connection, an empty lead is created. If you comment out the line
$this->curl_b24("https://{$this->bitrix24domen}/crm/configs/import/lead.php?LOGIN=". urlencode($this->bitrix24login) . "&PASSWORD=" . urlencode($this->bitrix24password));

Then the code does not come.
Has anyone encountered a similar problem, how can it be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Panteleev, 2018-10-25
@s_panteleev

See Bitrix24 REST documentation and how to get/renew tokens -
https://dev.1c-bitrix.ru/learning/course/index.php...
or use PHP SDK - https://github.com/mesilov/bitrix24 -php-sdk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question