MATLAB: EMBL RESTful API post request error

emblMATLABrestful apiweboptionswebwrite

Hello,
I would like to post a request to the EMBL RESTful API (well known Bioinformatics database) to get data relative to two different IDs (as an example: ENSG00000157764 and ENSG00000248378) but I am encountering the following error:
server = 'https://rest.ensembl.org';
ext = '/lookup/id';
data = '{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }';
options = weboptions('ArrayFormat','json','MediaType','application/json','HeaderFields',{'Content-Type' 'application/json';'Accept' 'application/json'},'RequestMethod','post');
r = webwrite([server,ext],data, options);
Error using webwrite (line 136)
Internal error: "curl_multi_remove_handle" failed with CURLMcode API function called from
within callback.
I am able to run this request using Python 3 like in there:
As part of the BioInformatics toolbox there are functions (getembl, emblread) but I cannot get them to work either.
Maybe it is a syntax problem or an option that I did not specify. I'll be happy to submit the MATLAB version for their website.
Thank you very much for the help!
Sandrine

Best Answer

You are almost there, except that MATLAB doesn't have a dictionary data type as Python3 has, so you should construct a struct instead:
getURL = 'https://rest.ensembl.org/lookup/id';
headers = {'Content-Type' 'application/json'; 'Accept' 'application/json'};
options = weboptions('RequestMethod', 'post', 'HeaderFields', headers, 'ArrayFormat', 'json');
data = struct('ids', ["ENSG00000157764", "ENSG00000248378"]);
r = webwrite(getURL, data, options)
struct with fields:
ENSG00000248378: [1×1 struct]
ENSG00000157764: [1×1 struct]