Open JVerbruggen opened 3 years ago
OpenRemote works with HTTP api calls. By hosting the environment locally, you can test these requests. The documentation [0] described that assets can be retrieved using a specific API call. These assets hold data such as wind turbine speeds and weather information.
Before being able to do another api call, we discovered realms, which seems to be some sort of environment that assets can be located in. The default realm is called master, and it should be specified when retrieving assets from the API.
We made a dummy publically available wind turbine asset to be able to retrieve something from our HTTP request. Then, by using postman, we found the correct endpoint, which correlates to the following pattern:
https://\<your-domain>/api/\<realm>/asset/public/query
If we apply this to us, we should use:
https://**localhost**/api/**master**/asset/public/query
Then, we read in the documentation that the request should be a POST request and that it should contain a body. We figured it would be a JSON body, so we tested it with the following:
{
"name": "Turbine1"
}
This resulted in a 200 OK HTTP Status code, which means success! We should still figure out how to selectively get an asset since we get all assets returned at this point. Also, we want the asset to be private, so we should take a look into authentication and authorization.
Open Remotes api works with queries, which are defined in java classes. If you structure your json request body according to the AssetQuery.java java structure, you will get the expected result.
The AssetQuery.java can be found here. It is important to mention that the methods on the bottom of the class determine the query, and not the classes on top, which was my initial thought.
An example:
{
"ids": [
"6dxd79p6PELw8rRirZnJFW"
]
}
In this case, I made a query selecting all assets that match the values in the ids array. This id here returns the WindTurbine asset we created earlier.
The next question will be: How will we push information from our wind power measurements to the API? In the end, we would like to be able to get this data from the OpenRemote API as well.
How do we communicate with open remotes app?