Hello everyone,
I am trying to access the API via my laravel application but i keep getting an error. Can someone please help me?
This is my code:
$payload = '{
"vehicles": [
{
"vehicle_id": "vehicle-1",
"type_id": "cargo-bike",
"start_address": {
"location_id": "berlin",
"lon": 13.406,
"lat": 52.537
},
"earliest_start": 1554804329,
"latest_end": 1554808329,
"max_jobs": 3
},
{}
],
"vehicle_types": [
{
"type_id": "cargo-bike",
"capacity": [
10
],
"profile": "bike"
}
],
"services": [
{
"id": "s-1",
"name": "visit-Joe",
"address": {
"location_id": "13.375854_52.537338",
"lon": 13.375854,
"lat": 52.537338
},
"size": [],
"time_windows": []
},
{
"id": "s-2",
"name": "serve-Peter",
"address": {
"location_id": "13.393364_52.525851",
"lon": 13.393364,
"lat": 52.525851
},
"size": []
},
{
"id": "s-3",
"name": "visit-Michael",
"address": {
"location_id": "13.416882_52.523543",
"lon": 13.416882,
"lat": 52.523543
},
"size": [
1
]
},
{
"id": "s-4",
"name": "do nothing",
"address": {},
"size": []
}
],
"shipments": [
{}
],
"objectives": [
{},
{}
],
"configuration": {
"routing": {
"calc_points": true,
"snap_preventions": []
}
}
}';
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://graphhopper.com/api/1/vrp?key=a79dmyapikeyd3b29', [
'headers' => [
//'User-Agent' => 'testing/1.0',
'Accept-Encoding' => 'gzip',
'Accept' => 'application/json',
//'X-Foo' => ['Bar', 'Baz']
],
'decode_content' => false,
'body' => json_encode($payload),
]);
And this is the error i get:
[2022-05-09 18:11:47] local.ERROR: Client error: `POST https://graphhopper.com/api/1/vrp?key=a79de7d9-ffe8-461e-a20b-95c03cdd3b29` resulted in a `400 Bad Request` response:
{"message":"Unsupported content type ","status":"finished"}
{"userId":1,"exception":"[object] (GuzzleHttp\\Exception\\ClientException(code: 400): Client error: `POST https://graphhopper.com/api/1/vrp?key=a79de7d9-ffe8-461e-a20b-95c03cdd3b29` resulted in a `400 Bad Request` response:
{\"message\":\"Unsupported content type \",\"status\":\"finished\"}
at D:\\WebServer\\ZeinTekWebServices\\liveroot\\merlin-core\\vendor\\guzzlehttp\\guzzle\\src\\Exception\\RequestException.php:113)