amocrm / amocrm-api-php

Библиотека на PHP для работы с API amoCRM
MIT License
143 stars 104 forks source link

Проблема с EventsFilter, нужна помощь #522

Closed mmmmlemon closed 9 months ago

mmmmlemon commented 9 months ago

Всем здравствуйте. У меня возникла проблема с EventsFilter. Я хочу получить список событий сделки по её id. Т.е у меня есть id сделки, и по нему я хочу отфильтровать ивенты. Если я правильно понимаю, то делается это как-то так:

$leadId = 25282325; //id сделки, хардкод
$eventsFilter = new EventsFilter(); //создаю фильтр
$eventsFilter->setEntityIds([$leadId]);

 try {
    $events = $apiClient->events()->get($eventsFilter);
    //дальше делаем что-нибудь с events
} catch (AmoCRMApiException $e){
   var_dump($e->getLastRequestInfo());
}

Но вылетает ошибка:

error

AmoCRM\Exceptions\AmoCRMApiException: Invalid http status in /public_html/amocrm/vendor/amocrm/amocrm-api-library/src/AmoCRM/Client/AmoCRMApiRequest.php:553 Stack trace: #0 /public_html/amocrm/vendor/amocrm/amocrm-api-library/src/AmoCRM/Client/AmoCRMApiRequest.php(604): AmoCRM\Client\AmoCRMApiRequest->checkHttpStatus(Object(GuzzleHttp\Psr7\Response), Array) #1 /public_html/amocrm/vendor/amocrm/amocrm-api-library/src/AmoCRM/Client/AmoCRMApiRequest.php(513): AmoCRM\Client\AmoCRMApiRequest->parseResponse(Object(GuzzleHttp\Psr7\Response)) #2 /public_html/amocrm/vendor/amocrm/amocrm-api-library/src/AmoCRM/EntitiesServices/BaseEntity.php(89): AmoCRM\Client\AmoCRMApiRequest->get('https://name...', Array) #3 /public_html/amocrm/amo.php(64): AmoCRM\EntitiesServices\BaseEntity->get(Object(AmoCRM\Filters\EventsFilter)) #4 {main}

Если через getLastRequestInfo() смотреть, то вот такое "Bad Request","type":"https://httpstatus.es/400","status":400,"detail":"Required param missed. You must specify filter."

getLastRequestInfo() полностью

array(10) { ["last_http_method"]=> string(3) "GET" ["last_method"]=> string(42) "https://name.amocrm.ru/api/v4/events" ["last_body"]=> array(0) { } ["last_query_params"]=> array(3) { ["filter"]=> array(1) { ["entity_id"]=> string(8) "25282325" } ["limit"]=> int(50) ["page"]=> int(1) } ["last_response"]=> string(169) "{"errors":{"key":"entity","value":null},"title":"Bad Request","type":"https://httpstatus.es/400","status":400,"detail":"Required param missed. You must specify filter."}" ["last_response_code"]=> int(400) ["last_request_id"]=> string(32) "15e982aa8b1b31789fda61e51163a9e2" ["jquery_call"]=> string(198) " $.ajax({ url: "https://egorproger.amocrm.ru/api/v4/events?filter%5Bentity_id%5D=25282325&limit=50&page=1", data: JSON.stringify([]), type: "GET", contentType: "application/json" });" ["curl_call"]=> string(110) "curl "https://name.amocrm.ru/api/v4/events?filter%5Bentity_id%5D=25282325&limit=50&page=1" -X "GET" -d""" ["timestamp"]=> int(1692259598) }

Что вообще значит "You must specify filter."? Пробовал фильтровать просто по id ивента, там таких проблем не было. Она возникает именно когда пытаешься применить фильтр entity_id.

Заранее спасибо за помощь.

mmmmlemon commented 9 months ago

Ну как всегда – половина проблем решается если просто надолго отойти от компьютера.

$leadId = 25282325; 
$eventsFilter = new EventsFilter(); 
$eventsFilter->setEntity(['lead']); //добавил вот эту строку
$eventsFilter->setEntityIds([$leadId]);

Если фильтруешь ивенты по entity_id, то нужно ещё указывать вид самой entity (не очень понимаю зачем, ну да ладно). Сразу не догадался.

Вообще, в examples не помешали бы примеры с events.