question

cdsahin avatar image
cdsahin asked

API - MATLAB Error

Hi Eveyone,


I have been trying to access the API data from MATLAB. However, I get en error of which screenshot is below. I am sure my credentials are correct.

Has anyone ever tried to pull the API data from MATLAB using RESTful request-response model?


VRM
1580825773980.png (43.0 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

1 Answer
Teun Lassche avatar image
Teun Lassche answered ·

Hi! Make sure that you write a JSON object, see the ‘Write JSON object’ section here: https://nl.mathworks.com/help/matlab/ref/webwrite.html

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

cdsahin avatar image cdsahin commented ·

Hi Teun,

Thank you. It worked! I managed to receive the 'token' and 'idUser'.

However, this time, I have another issue regarding using the 'token' and 'idUser' information to pull the API data. Do you have any suggestion about how it can be done? Somehow, I should find a way to use the 'token' and 'idUser'.

Here are my code and error message:

url = 'https://vrmapi.victronenergy.com/v2/auth/login'

data = jsonencode(struct('username','***','password','***'))

response = webwrite(url,data)

headerFields = {'Authorization', ['Bearer ', response.token]};
options = weboptions('HeaderFields', headerFields, 'ContentType','json');

url2 = ('https://vrmapi.victronenergy.com/v2/users/'+ string(response.idUser) +'/installations')

resp2 = webwrite(url2,options);

0 Likes 0 ·
1580869010873.png (14.3 KiB)
1580869296248.png (14.2 KiB)
Show more comments