0

Делаю запрос POST на teamleader API, в котором надо указать имя пользователя и его емаил, но каждый раз пишет это:

string(442) "{"errors":[{"code":0,"title":"Each item in emails must be valid","status":400,"meta":{"field":"emails"}},{"code":0,"title":"Key type must be present","status":400,"meta":{"field":"type"}},{"code":0,"title":"Key email must be present","status":400,"meta":{"field":"email"}},{"code":0,"title":"Key type must be present","status":400,"meta":{"field":"type"}},{"code":0,"title":"Key email must be present","status":400,"meta":{"field":"email"}}]}"

Ввожу разные емайлы, ничего не работает. Запрос: `

$postdata = array("last_name" => "Stas ", "emails" => array("type" => "primary", "email" => $state));   
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.teamleader.eu/contacts.add");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);

        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    "Content-Type: application/json;charset=utf-8",
                    'Authorization: Bearer ' . $access_token,
                ));
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata));

https://developer.teamleader.eu/#/reference/crm/contacts/contacts.add - вот апи, делаю как тут и ничего `

1 ответ 1

1

emails должен быть массивом объектов, а у вас сразу идет объект

ваш код

'emails' => array(
    'type' => 'primary', 
    'email' => $state
);

должно быть

'emails' => array(
    array(
        'type' => 'primary', 
        'email' => $state
    )
);
1
  • Спасибо большое, работает, долго не мог понять в чем дело
    – LoopEx
    3 июл 2019 в 12:29

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.