How can I import "curl" API in MATLAB using webread function?

I am trying to import a dataset from a website (https://www.sapsailing.com/sailingserver/webservices/api/v1/) using their API. The specific website to use (from their example) is: curl "https://www.sapsailing.com/sailingserver/api/v1/regattas/Kornati%20Cup%202019%20-%20B46/races/B46%20R1/startanalysis"
In the case above, I believe my issue is the "curl" portion of the website. I am unsure what this is or how to code it into MATLAB. I tried the following:
api_url = 'https://www.sapsailing.com/sailingserver/api/v1/regattas/Kornati%20Cup%202019%20-%20B46/races/B46%20R1/startanalysis';
api = webread(api_url);
With this error message:
Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray
The server returned the status 404 with message "Not Found" in response to the request to URL
https://www.sapsailing.com/sailingserver/api/v1/regattas/Kornati%20Cup%202019%20-%20B46/races/B46%20R1/startanalysis.
Error in readContentFromWebService (line 46)
byteArray = copyContentToByteArray(connection);
Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
I also included "curl" in the webread function, but that did not work either.
I am able to import data from a similar website using this code:
api_url = 'http://www.sapsailing.com/sailingserver/api/v1/leaderboards';
api = webread(api_url);
I appreciate any help.
Thank you,
Josh

 Réponse acceptée

Jan
Jan le 28 Avr 2022
Modifié(e) : Jan le 28 Avr 2022
What about using curl instead? This is included in Linux, MacOS and Windows also:
system(['curl "https://www.sapsailing.com/sailingserver/api/v1/regattas/', ...
'Kornati%20Cup%202019%20-%20B46/races/B46%20R1/startanalysis"'])
The web service replies: "Could not find a regatta with name 'Kornati Cup 2019 - B46'"
So there seems to be another problem.

3 commentaires

Thank you, this definitely helps.
I tried another race using this code:
system(['curl "https://www.sapsailing.com/sailingserver/api/v1/regattas/', ...
'Hempel%20World%20Cup%20Series%202022%20-%20Round%201%20ILCA%206/races/ILCA%206%20GOLD%20-%20Race%2010/maneuvers"']);
It looked like it worked, however I got this message:
Output truncated. Text exceeds maximum line length for Command Window display.
Do you have any tips on how I can save these data in a table within the MATLAB workspace or export them as a csv? This is the first time I've used the "system" command. Thank you for teaching me that!
Try:
system('curl "insert your URL">D:\YourFolder\FileName')
to write the output to a file instead of displaying it in the command window.
That worked geat. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by