I use the following commands to get a Curl response from an Api:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://{api-url_goed_here}/api/v2/token",
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"grant_type": "password","client_id": "'.$client_id.'","username":"'.$username.'","password":"'.$user_password.'"}',
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$responseArray = curl_exec($curl);
$err = curl_error($curl);
I get a response. It looks like an array when I use print_r($responseArray). But when I use var_dump($responseArray), I see that it actually a string:
string(384) "Array
(
[access_token] => #token_is_here
[token_type] => bearer
[expires_in] => 3600
[refresh_token] => #refresh_token_is_here
[uid] => 7
[info] => Array
(
[name] => #name_is_here
[code] => #some_code
[email] => #some_mail_address
)
[policy] => Array
(
[write_hours] => 1
)
)
"
How do I prevent to get a string as response? I'm aiming to get an array, because I want to extract the access_token
print_r()when it should be usingecho json_encode(). Perhaps the API devs accidentally left some debugging code in there?