I'm having problems converting curl to php, I need to access data in json and filter this data. I was able to access the data without the filter but I can't access it when I add the filter.
The code below is functional and brings all the data in json...
`
<?php
$apikey = 'my api key';
$outputType = 'json';
$url = 'https://bling.com.br/Api/v2/contasreceber/' . $outputType;
$retorno = executeGetOrder($url, $apikey);
echo $retorno;
function executeGetOrder($url, $apikey){
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url . '&apikey=' . $apikey);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl_handle);
curl_close($curl_handle);
return $response;
}
?>
`
This was the code I tried to run to apply the filters as the developer described.
As stated in the developer's api manual https://ajuda.bling.com.br/hc/pt-br/articles/360047064873-GET-contasreceber
I would be very grateful if someone could help me my knowledge is limited and I don't know where I'm going wrong.
`
<?php
$apikey = 'myapikey';
$outputType = 'json';
$url = 'https://bling.com.br/Api/v2/contasreceber/' . $outputType;
$retorno = executeGetOrder($url, $apikey);
echo $retorno;
function executeGetOrder($url, $apikey){
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url . '&apikey=' . $apikey);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'filters=dataEmissao[01/01/2022 TO 05/02/2022]; situacao[Aberto]');
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl_handle);
curl_close($curl_handle);
return $response;
}
?>
`
CodePudding user response:
When I look on your documentation, date
does not exist.
You can only have as filters :
- dataEmissao * ;
- dataVencimento * ;
- situacao ;
- cnpj ;
- dataPagamento *;
The ones I put *
are the filters with date inputs so you need, depending of your wanted :
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'filters=dataEmissao[01/01/2022 TO 05/02/2022]; situacao[open]');
CodePudding user response:
An alternative when making a get request.
<?php
$apikey = 'my api key';
$outputType = 'json';
$filters ="cnpj[21.416.959/0001-82]";
$url = 'https://bling.com.br/Api/v2/contasreceber/' . $outputType;
$retorno = executeGetOrder($url, $apikey, $filters);
echo $retorno;
function executeGetOrder($url, $apikey, $filters){
return file_get_contents( $url.'&apikey=' . $apikey . '&filters=' . $filters`);
}
?>