I'm trying to use cURL POST to get some data from an endpoint:
Here is what the documentation says to authenticate and get data:
"...uses a combination of OAuth2 grant_types and JWT tokens
To authorize, use this code:
curl -X POST \
'http://api.example.com/v1/api/auth/login?grant_type=client_id' \
-H 'Authorization: Basic cHVibGljX2tleTpwddl2YXRJX2xleQzd'
"
Based on the info above, I built this code for the request:
$handle = curl_init('http://api.example.com/v1/api/auth/login?
grant_type=client_id');
$header = array();
$header[] = 'Content-Type: application/json';
$header[] = 'Authorization: Basic DdJfd1Bxx2NxMkYwNjzzdl9mejJZIFKVQlBc';
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $header);
$resp = curl_exec($handle);
var_dump($resp);
When I execute the code, it runs in an endless loop and eventually times out.
Is the format of the code correct or is it a problem with the authorization key I provided? The key is a Base64 representation.
Thanks!
UPDATE: I've tried the following also:
$header[] = 'Content-Type: application/json';
$header[] = 'Authorization: Basic adfsidfosfosfodsofs';
$content = "grant_type=client_id";
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);