Receiving Data from openremote via REST API

Hi,

i might struggle a bit to understand how to receive data from openremote via REST API. I receive data on openremote via MQTT and want to receive the data on my app via REST API from openremote.

I had a look at the User Guide on Github for APIs but couldn’t find anything specific for my case. Also searching the forum didn’t help me to understand how it works.

Do i need to create an additional Asset? I also found the swagger OpenRemote Manager REST API. Do i just call the MQTT Agent here? which URL do i have to use here?

Sorry for that many questions, i just feel like i can’t find the solution here (first IoT project here and happy i got the MQTT running)

Kind regards,

Tim

Hi and welcome,

The OpenRemote HTTP API is described in the live swagger documentation OpenRemote Manager HTTP API Swagger UI.

To be able to use it you will need to create a service user with permissions to read and/or write.

It’s hard to figure out exactly what you’re trying to do but sounds like you want to use a HTTP client to make requests to OpenRemote via the HTTP API (to retrieve attribute values?).

HTTP is not the right tool for this purpose being a request-response protocol, websocket or MQTT would be more preferable as they are publish-subscribe so you could listen for updates to the attribute(s) rather than using HTTP polling.

Hey rich,

thanks for your quick reply and sorry for mine being so late. You’re right with your assumption on how i want to use it. I’ll give i a try to explain it a bit more.

I’m receiving sensor data from a database via MQTT on openremote. The plan for now is to visualize the data on OpenRemote and send it further to an App. The App would only do GET requests to receive the data and in OpenRemote a rule would update the values for the http requests (this was my idea so far).

As it’s an university project for my studies, my supervisor told me i should look for different protocols to use. But if it’s not possible, i’ll stick to MQTT :slight_smile:

So i got it right that there is no possibility to access the sensor data on OpenRemote via HTTP API on my App? I had a deeper look at the swagger documentation but i’m not sure if this is the key to what i’m planning .

Thanks again for any reply and help!

Kind regards,

Tim

HTTP is just not the protocol for publish subscribe type data.

If you want to explore other protocols then there is the websocket API which is for publish subscribe type requests and you should find some explanation in the wiki.

Kind regards,

Rich

My idea is not to publish data to via HTTP. In my App i want to receive a value as soon as a trigger is hit, so i don’t need to listen to the server. I thought HTTP as request-response protocol would be the right protocol for this scenario.

when i go to users i just get a blank white page

As i’m trying to get into the demo documentation on Swagger, i’m quite sure that i need to authorize before being able to make requests as i’m getting response errors for forbidden access.
So when i authorize on this
image
and log in with my admin account i receive this error even if i enable cookies for everything.
image

I also receive an internal error when i’m trying the Authenticator for my Account (not sure if this needs to be done in advance)

Is there anything i’m missing and that needs to be enabled in ManagerUI?

Kind regards,

Tim

To create/update users you need to be logged in as a user with those roles for example the default admin user.

Note that due to limitations in swagger UI you can only use the swagger UI for the master realm (i.e. you cannot configure the token URI that swagger uses in order to authorise a different realm).

Request Response protocols like HTTP work well when you are requesting something but what you describe as “receive a value as soon as a trigger is hit” doesn’t fit with this model and has traditionally been handled using some form of long polling which is in-efficient. Hence publish subscribe type protocols are a much better fit for this.

Kind regards,

Rich

I just realized that i changed the password for admin and due to that i couldn’t see users anymore. As i changed it back i was able to see all of it again.

When i’m trying to authorize the user (created in admin mode) on swagger (localhost) i receive “Invalid parameter: redirect_uri”. User has access to everything and exists otherwise i receive the message “Client not found”.
image
image
the link that appears looks like this:
https://localhost/auth/realms/master/protocol/openid-connect/auth?response_type=code&client_id=userall&redirect_uri=https%3A%2F%2Flocalhost%2Fswagger%2Foauth2-redirect.html&state=TW9uIEp1biAxMyAyMDIyIDIyOjU2OjI0IEdNVCswMjAwIChNaXR0ZWxldXJvcMOkaXNjaGUgU29tbWVyemVpdCk%3D

when i’m trying to get the access token via the URL like in the user guide:
/auth/realms/{realm}/protocol/openid-connect/token
https://localhost/auth/realms/master/protocol/openid-connect/token
i receive

and for the authentification
https://localhost/auth/realms/master/protocol/openid-connect/auth
i receive

Any tips to get the authentification and token?

Kind regards,

Tim

1 Like

Hi,

Apologies I sent you down a bit of a rabbit hole with service users and swagger :slight_smile:

Swagger isn’t configured to support client_credentials grant type which is what service users use.

Swagger didn’t/doesn’t have a lot of flexibility with runtime OAuth configuration unfortunately.

Instead you can just login as a regular user by leaving the client_id as openremote and leave the client_secret blank.

Rich

1 Like

Hi,

so i’m able to authorize via the default client_id/secret but i still receive 403: Forbidden access. I think it’s due to the missing authorization header/ token that i can’t request (still receiving internal server error while trying to request the token as in the post above).
image

How can i receive the token if i can’t use the endpoint?
image
I need the token for the Header to authorize my request i guess
image

Kind regards,

Tim

You should be able to authenticate and also make requests using the Swagger UI.

As for using some other client then the service user approach is the correct way to go and to then ensure that the created service user is assigned the appropriate permissions.

You should then be able to follow the client_credentials OAuth2.0 flow to get an access token and to then use this in your HTTP requests Authorization header as a Bearer token.

Hi @Rich ,

we have managed to get the token using a newly created user and secret from open remote, however we are receiving 403 forbidden while using the returned token.

Note : we also receiving the below error in the manager:emote.container.web.WebServiceExceptions : Web service exception in ‘RESTEasy Role Security’ for ‘POST http://57.217.164.84:8443/provisioning’, root cause: javax.ws.rs.ForbiddenException: Only super admin can create provisioning configurations

please check our post request as below :

so could you please help me out on this ?

Thanks,
Marwan ElAdawy

Hi,

So you have managed to authenticate successfully; the 403 indicates an authorisation issue and that is because the endpoint you are calling is only intended to be used by super users; with the latest manager docker image you should be able to add the super user realm role to a user. Long term we will add a dedicated role for device provisioning CRUD operations.

Hi
Trying to get authorization token as recommended on wiki, https://198.177.125.69/auth/realms/master/protocol/openid-connect/token
But getting error, can you please help me resolve it.

Does it work from Swagger?

Please provide keycloak container logs which might contain details of the error