-1
Good Morning,
I am taking data from an API and it returns me 100 records per page, however it does not tell me how many pages there are of record. The only information that is passed to me is when you find no more data, as an example below;
{
"retorno": {
"erros": [
{
"erro": {
"cod": 14,
"msg": "A informacao desejada nao foi encontrada"
}
}
]
}
}
What I’m not able to do is paging to get the data until the API returns the error. Below is part of my code.
$apikey = "{apikey}";
$outputType = "json";
$page = 1;
$url = 'https://site.com.br/Api/v2/pedidos/page=' .$page. '/' . $outputType;
$retorno = $this->executeGetContacts($url, $apikey);
foreach($retorno as $erro){
if(isset($erro->erros[0]->erro->cod) == 14){
echo ('Pedidos cadastrados');
}else{
foreach($retorno as $pedidos){
for($page; $page < count(); $page++)
}
}
}
Thank you very much
Version of Laravel?
– Lucas Antonio
I’m using the 5.8
– shadow
Laravel already has paginate if you want to put an example code
– Lucas Antonio
It wouldn’t be paginar. What I want to do is when the API I’m picking up the data, return me the 100 records the variable $page has to go incrementing to get the other 100 data from the API, until the API returns me the code 14 and falls into the if
– shadow
you can only pass a data limit in the query and returns as much right without this whole revolution
– Lucas Antonio
Could you give me an example?
– shadow