POST elevation API use in MATLAB

Hi all,

I am trying to use the POST elevation API in Matlab. I succeeded with GET, but want to go deeper.
I have tried this, but it doesnt work:

url = 'https://api.openrouteservice.org/elevation/line';
hf = {'Accept','application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8';...
    'Authorization','<api_key>';...
    'Content-Type','application/json; charset=utf-8'};

options = weboptions('CharacterEncoding','utf-8','RequestMethod','POST',...
    'HeaderFields',hf,'ArrayFormat','json','MediaType','application/json','ContentType','json');


Body = struct('format_in', 'polyline', ... 
          'format_out', 'polyline', ...
          'dataset', 'srtm', ...
          'geometry', '[[13.331302,38.108433],[13.331273,38.10849]]');
Body = struct('order', Body);
response = webwrite(url, Body, options);

But matlab gives the following error:
Error using readContentFromWebService (line 46)
The server returned the status 400 with message "Bad
Request" in response to the request to URL
https://api.openrouteservice.org/elevation/line.

Could anyone help? Thanks in advance.

Regards,

Thomas

Please use proper code formatting.

Not our team I fear, sorry. No idea about matlab syntax. Though this looks fishy to me:

options = weboptions(‘CharacterEncoding’,‘utf-8’,‘RequestMethod’,‘POST’,… ‘HeaderFields’,hf,‘ArrayFormat’,‘json’,‘MediaType’,‘application/json’,‘ContentType’,‘json’);

How does Matlab know which header key belongs to which header value? Or are these function arguments and that’s just the order it expects?

Probably your question is better suited in a matlab forum as it’s a basic programming mistake, not a problem with openelevationservice.

Thank you for your quick response. Matlab is supposed to know because I introduced the header “hf” containing all additional headers. Good advice, I will contact Matlab.