I have api address of a software which I need to create a PHP form and fetch this data.
URL Ex: " link "
With the URL, the following example is provided:
Object: Product
GET /api/produto/listar
Parameters:
? product = 1 & color = 16 & format = json
I've never consumed an API with PHP.
Can anyone give me a hint, example, indicate a link, story, something so that I can start consuming this api?
I tried the following, but it does not return all the fields:
in var_dump it returns me like this:
string (502) "5"
My code looks like this:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "http://ip:porta/api/lista_departamento?cod_departamento=001&$format=json");
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
echo $result;
?>
When I pass the url in the browser it returns me like this:
{"odata.metadata":"http:\/\/ip:porta\/api\/$metadata#site_join.SITE_JOIN_DEPARTAMENTOS_LISTA","odata.count":1,"value":[{"departamento":20,"cod_departamento":"001","descricao":"MASCULINO"}]}