Hi!
I´m trying to use the example from API Playground and all I get is error_message:500
What am I doing wrong?
---- Extract ----
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.openrouteservice.org//pois?api_key=...);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, '
{
"request":"POIS",
"sortby":"distance",
"geometry":{
"geojson":{
"type":"Point",
"coordinates":[8.807099091203672, 53.07528723347236]
},
"bbox":[[8.807054, 53.075024], [8.807533, 53.075363]],
"buffer":50
}
}'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json; charset=utf-8"));
$response = curl_exec($ch);
curl_close($ch);
?>
nils
December 27, 2018, 2:35pm
2
First, please provide a request we can verify… I.e. in curl
form.
But request=POIS
--> request=pois
should already solve it…
nils,
The lines after “---- Extract —” are exactly the same as the example code for PHP at
https://openrouteservice.org/dev/#/api-docs/pois/post
When I press “Call Action” it works fine, but when I use this code at my script it returns the error message.
timothy
December 27, 2018, 4:49pm
4
@uerlings as Nils mentioned, please send us the request as cURL and we will inspect. Cheers, Tim
curl --include \
--request POST \
--data '{"request":"pois","geometry":{"bbox":[[8.8034,53.0756],[8.7834,53.0456]],"geojson":{"type":"Point","coordinates":[8.8034,53.0756]},"buffer":250}}' \
--header "Accept: application/json; charset=utf-8" \
'https://api.openrouteservice.org/pois?api_key=....'
timothy
December 27, 2018, 6:05pm
6
@uerlings There seems to be some misbehaviour in the generation of the POST body in the documentation, we will look into it. Please try this for now:
curl -X POST \
'https://api.openrouteservice.org/pois?api_key=XYZ' \
-H 'Content-Type: application/json' \
-d '{
"request": "pois",
"geometry": {
"bbox": [[8.8034,53.0756],[8.7834,53.0456]],
"geojson":{
"type":"Point",
"coordinates":[8.8034,53.0756]
},
"buffer":250
},
"limit": 20
}'
timothy
December 27, 2018, 6:12pm
7
After investigating, the difference is the header, please for now use
-H 'Content-Type: application/json'
Thank you, Tim
Thanks Tim and nils!
It worked with cURL.
I´ve managed to adjust for PHP curl
$postfields = array(
“request”=>“pois”,
“geometry”=>[
“bbox”=>[[8.8034,53.0756],[8.7834,53.0456]],
“geojson”=>[
“type”=>“Point”,
“coordinates”=>[8.8034,53.0756]
],
“buffer”=>250
]
);
$extra = json_encode($postfields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.openrouteservice.org/pois?api_key=5b3ce3597851110001cf624822e32ca1fb68454ca6525722efb2b6f7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $extra);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'charset=utf-8'
)
);
$response = curl_exec($ch);
curl_close($ch);
Happy New Year!