0

Estoy intentando hacer esta petición post por medio de curl, pero no me funcion, en las indicaciones dice esto:

I've got an API Key... How can I make an API request? You can send your requests with an Authorization Header with a value like this: Authorization: apiKey {api_key}.

Example using curl:

curl -H "Authorization: apiKey {api_key}" https://api.connectif.cloud Important notes Connectif HTTP API is open, it means that we do not have to add your IP's in a whitelist.

Intente con esto:

curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.connectif.cloud/purchases/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => array(
    'apiKey: aquipusemiapi',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl); echo $response;

Pero me lanza que la autenticación no es correcta. Podrían apoyarme por favor.

1
  • 1
    El header es Authorization. array('Authorization: apiKey <api_key>', ... el 18 may. 2021 a las 16:46

1 respuesta 1

2
+25

El header del ApiKey no es correcto. Debería de ser 'Authorization: apiKey aquipusemiapi' en vez de 'apiKey: aquipusemiapi'. El código quedaría así:

curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.connectif.cloud/purchases/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => array(
    'Authorization: apiKey aquipusemiapi',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.