HERE RESTful API - POST - Fleet Telematics

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.

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 24 de Jun. de 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 comentarios

Sridhar Eswaran
Sridhar Eswaran el 25 de Jun. de 2020
Editada: Geoff Hayes el 25 de Jun. de 2020
Hi Geoff,
Thank you for your input. I tried your suggesstion, but I am stil getting the error.
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.
Error in readContentFromWebService (line 46)
byteArray = copyContentToByteArray(connection);
Error in webwrite (line 139)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in Untitled (line 5)
response = webwrite(url,payload,options);
Geoff Hayes
Geoff Hayes el 25 de Jun. de 2020
Sridhar - does the AudiRoute_Section01.gpx payload match the xml that you pass via --data-raw?
Sridhar Eswaran
Sridhar Eswaran el 25 de Jun. de 2020
Geoff, It does. So far I have been using 'POSTMAN' application to send this requests and save the response as JSON and post-process it in MATLAB. I have copy, pasted the same cURL code generated by the application in the question.
You could confirm if the payload variable looks to be as expected (i.e. an xml string). Otherwise, I'm not sure what is incorrect - the 400 error still suggests a problem with the request.
Alternatively, you can (probably) call the curl from within MATLAB using the system command like
command = '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(*)''';
command = [command ' --header ''Content-Type: text/plain'''];
command = [command ' --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>'''];
[status, output] = system(command);
assuming that the correct app_id and and app_code are used.
Sridhar Eswaran
Sridhar Eswaran el 26 de Jun. de 2020
Hi Geoff,
I tried the method you suggested. Still getting error same error. May be I am doing something wrong here. Lemme try again and get back to you. Please suggest if you have any other methods.
Really appreciate your help. Thanks.
Geoff Hayes
Geoff Hayes el 26 de Jun. de 2020
Hi Sridhar - I tried with the above code using system and it worked so long a valid app code and id were used.
Sridhar Eswaran
Sridhar Eswaran el 29 de Jun. de 2020
Hi Geoff, I will reacquire a new app id, app code and try your suggestion. Will let you know the outcome. Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Desktop en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Preguntada:

el 24 de Jun. de 2020

Comentada:

el 29 de Jun. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by