1
Good staff make a request in the pay.me API for me to recover some credit card data. When I use directly by the terminal with this code, I receive JSON correctly with all data requested:
curl -X GET https://api.pagar.me/1/transactions/ID_transacao -H 'content-type: application/json' -d '{
"api_key": "CHAVE_API"
}'
But when I try to move to php I don’t know what I’m doing wrong, as I get the following error that my parameters are incorrect from paying.
{"errors":[{"type":"invalid_parameter","parameter_name":"api_key","message":"api_key está faltando"}],"url":"/transactions/ID_transacao","method":"get"}
My PHP code is as follows:
$date = array(
"api_key" => "CHAVE_API"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, "https://api.pagar.me/1/transactions/ID_transacao");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, 'content-type: application/json');
curl_setopt($ch, CURLOPT_POSTFIELDS, $date);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
What would be the correct way to pass this parameter?
Pay API link.me: https://docs.pagar.me/reference
NOTE: I have to use Curl to make this request, I cannot use their API for Php.
It seems to me that the problem is this configuration "curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');", but api_key is sent by POST, take a look at the documentation in https://www.php.net/manual/en/function.curl-setopt.php.
– Benilson