0

I am trying to get the collector list and keep getting a 401 response "The authorization token was not provided."

I can't understand what am I doing wrong:

$auth_data = [
    'Authorization : bearer ' . $accessToke,
    'contentType : application/json',
];

$cURLConnection = curl_init();

curl_setopt($cURLConnection, CURLOPT_URL, 'https://api.surveymonkey.com/v3/surveys/119550392/collectors');
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $auth_data);
$list = curl_exec($cURLConnection);
curl_close($cURLConnection);

echo "<pre>";
print_r($list);
echo "</pre>";

thanks

0

1 Answer 1

1

You have typo in your headers declaration. According to HTTP specification, there is no white space between header name and :

Each header field consists of a case-insensitive field name followed
by a colon (":"), optional leading whitespace, the field value, and
optional trailing whitespace.

So

$auth_data = [
    'Authorization: bearer ' . $accessToke,
    'Content-Type: application/json',
    'Accept: application/json'
];

Note that I also fixed contentType to Content-Type and added Accept headers

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.