HERE RESTful API - POST - Fleet Telematics
2 views (last 30 days)
Show older comments
Sridhar Eswaran
on 24 Jun 2020
Commented: Sridhar Eswaran
on 29 Jun 2020
Hi, How can I send this request in matlab?
/////
curl --location --request POST 'https://fleet.cit.api.here.com/2/calculateroute.json?routeMatch=1&mode=car&app_id=ABCDEFGHIJK&app_code=ABCDEFGHIJK&attributes=ROAD_GEOM_FCn(*),%0ASPEED_LIMITS_FCn(*)' \
--header 'Content-Type: text/plain' \
--data-raw '<?xml version="1.0" encoding="UTF-8" standalone="no"?><gpx version="1.0" creator="ITN Converter 1.94M (http://www.benichou-software.com)" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xmlns:topografix="http://www.topografix.com/GPX/Private/TopoGrafix/0/2" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.topografix.com/GPX/Private/TopoGrafix/0/2 http://www.topografix.com/GPX/Private/TopoGrafix/0/2/topografix.xsd"><time>2020-06-22T11:22:23Z</time><bounds minlat="49.274710" minlon="9.223330" maxlat="49.288730" maxlon="9.242580"/><rte><name>Route_from_Peter</name><rtept lat="49.274710" lon="9.223330"/><rtept lat="49.274740" lon="9.223380"/><rtept lat="49.274840" lon="9.223540"/><rtept lat="49.275030" lon="9.223830"/><rtept lat="49.275160" lon="9.224100"/><rtept lat="49.275260" lon="9.224290"/>...........................<rtept lat="49.288230" lon="9.241680"/><rtept lat="49.288280" lon="9.241760"/><rtept lat="49.288340" lon="9.241850"/><rtept lat="49.288390" lon="9.241920"/><rtept lat="49.288440" lon="9.241990"/><rtept lat="49.288560" lon="9.242200"/><rtept lat="49.288730" lon="9.242580"/></rte></gpx>'
/////
I have used this code,
/////
url = 'https://fleet.cit.api.here.com/2/calculateroute.json?routeMatch=1&mode=car&app_id=ABCDEFGHIJK&app_code=ABCDEFGHIJK &attributes=ROAD_GEOM_FCn(*),SPEED_LIMITS_FCn(*)';
weboptions('ContentType','text','RequestMethod','POST')
payload = fileread('AudiRoute_Section01.gpx');
response = webwrite(url,payload);
////
The response was,
////
Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray (line 396)
The server returned the status 400 with message "" in response to the request to URL
https://fleet.cit.api.here.com/2/calculateroute.json?routeMatch=1&mode=car&app_id=ABCDEFGHIJK&app_code=ABCDEFGHIJK&attributes=ROAD_GEOM_FCn%28%2A%29,SPEED_LIMITS_FCn%28%2A%29,ADAS_ATTRIB_FCn%28%2A%29,LINK_ATTRIBUTE_FCn%28%2A%29.
Error in readContentFromWebService (line 46)
byteArray = copyContentToByteArray(connection);
Error in webwrite (line 139)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in rest (line 4)
response = webwrite(url,payload);
///
Can anyone help here?
Thanks in Advance.
0 Comments
Accepted Answer
Geoff Hayes
on 24 Jun 2020
Sridhar - the 400 error code indicates (if I recall correctly) that there is a problem with your request. I see that you call
weboptions('ContentType','text','RequestMethod','POST')
but that you don't do anything with the result of that call. I think that your code could be more like
url = 'https://fleet.cit.api.here.com/2/calculateroute.json?routeMatch=1&mode=car&app_id=ABCDEFGHIJK&app_code=ABCDEFGHIJK &attributes=ROAD_GEOM_FCn(*),SPEED_LIMITS_FCn(*)';
options = weboptions('ContentType','text','RequestMethod','POST');
payload = fileread('AudiRoute_Section01.gpx');
response = webwrite(url,payload,options); % <--- include the options as a parameter of webwrite
I can't test the above so I don't know if it will work (especially with the payload) but it might get you a little further.
7 Comments
Geoff Hayes
on 26 Jun 2020
Hi Sridhar - I tried with the above code using system and it worked so long a valid app code and id were used.
More Answers (0)
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!