AmoCRM PHP API/oAuth Client
$invoice = $amo->catalogElements()->find(1507445); $cf = $invoice->cf()->byCode('BILL_CREATED_AT'); echo $cf->code;
$activity = $user->getActivity($from = date('d.m.Y'), $to = date('d.m.Y'));
Added new callback args: $query, $response
$amo->onAccessTokenRefresh(function($oauth, $query, $response) {
echo $query->startDate().' - ['.$query->method.'] '.$query->getUrl()."\n";
print_r($query->post_data);
echo $query->endDate().' - ['.$response->getCode().'] '. $response->getData(). "\n\n";
echo "\nRefreshed oauth: \n";
print_r($oauth);
});
$amo->onAccessTokenRefreshError(function($exc, $query, $response) {
echo $query->startDate().' - ['.$query->method.'] '.$query->getUrl()."\n";
print_r($query->post_data);
echo $query->endDate().' - ['.$response->getCode().'] '. $response->getData(). "\n\n";
exit('Error refresh token: '.$exc->getMessage().', code: '.$exc->getCode());
});
Added randomly refresh time for token expiration check.
if ($expire_time < $instance->queries->getRefreshTime()) {
$this->instance()->refreshAccessToken();
$oauth = $instance->getOauth();
}
$amo->onAccessTokenRefreshError(function($exception) { echo 'Refresh token failed: '.$exception->getMessage().', code: '.$exception->getCode(); });
$elems = $crm->companies()->searchByName('OOO best', 100);