Issues with authentication using Restful API
Mostra commenti meno recenti
I am using an LED lightsource which is controlled via Restful API. A json encoded string needs to be sent to a specific url address depending on the command. The below line is from the documentation on how to login.

I have achieved this using the following code:
base_url = "http://192.168.7.2:8181/";
command = "api/login";
login.username = "admin";
login.password = "d597cc7b6fca9295";
url = base_url.append(command);
login_json = jsonencode(login);
opt = weboptions('RequestMethod', 'post','MediaType','application/json' ,'Debug', true);
response = webwrite(url, login_json, opt);
The issue I am having is that the documentation says that the retuned object needs to be used as an input argument when calling the other commands.
For example, I want to use the following command:

The following code does not work as it is not passing the login retun object.
command = "api/luminaire/1/command/SET_COLOR";
url = base_url.append(command);
data.arg = [0.5, 0.5, 3400];
data_json = jsonencode(data);
Is there anyway to achieve this with the webwrite and webread functions? Or is there an alternative way? Currently I have it working through python, but I want to get away from calling python code through matlab.
Please note that I have tried including credentials within the weboptions, however as this doesn't allow the url to be included this doesn't do anything.
Any help would be greatly appreciated.
Kind regards,
Robert
2 Commenti
Geoff Hayes
il 31 Ago 2022
@Robert Phipps - you say that the "returned object needs to be used as an input argument when calling the other commands". But from your second example, it isn't clear where the response from the first API request is used. Is there a token that you need to add in your header?
Robert Phipps
il 31 Ago 2022
Risposte (0)
Categorie
Scopri di più su Call Web Services from MATLAB Using HTTP in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
