# Using Rest APIs in OpenEMS

**URL:** <https://community.openems.io/t/using-rest-apis-in-openems/1625>\
**Category:** English Forum\
**Created:** [June 5, 2023, 12:51pm UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625 "2023-06-05T12:51:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsen](https://community.openems.io/letter_avatar_proxy/v4/letter/d/6de8d8/32.png) [@dsen](https://community.openems.io/u/dsen)\
**Post date:** [June 5, 2023, 12:51pm UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/1 "2023-06-05T12:51:31Z")

</div>

Hello All :),  
I would like use OpenEMS to monitor a PV device via Rest APIs. I’m not able to find satisfactory documentation about the setup and use of the controllers available. Specifically:

How do I start the API service? [Is it running by default/ do I make a change in the config files]  
When I save a controller in the Apache ConfigManager, I get webSocket errors.

In general, are there any code samples/Documentation/Guides for how to use the various components? How do I go about getting familiar with the OpenEMS environment?

Warm Regards,  
Dipti

---

<div class="post-metadata">

**Author:** ![p.wimmer](https://community.openems.io/user_avatar/community.openems.io/p.wimmer/32/50_2.png) [@p.wimmer](https://community.openems.io/u/p.wimmer)\
**Post date:** [June 8, 2023, 12:45pm UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/2 "2023-06-08T12:45:02Z")

</div>

Hello,  
no there are not so many documentations out, yet. Cause most of us are full with workload :D.  
just start the alphabeticSchedular and the “Rest Api”, than you can talk to openems by rest.

for example [http://localhost:8084/rest/channel/meter0/ActivePower](http://localhost:8084/rest/channel/meter0/ActivePower) with an meter with id “meter0” you get so the ActivePower.

“When I save a controller in the Apache ConfigManager, I get webSocket errors.” this is a bit to less information to help you ;).

---

<div class="post-metadata">

**Author:** ![JimsterCoder](https://community.openems.io/user_avatar/community.openems.io/jimstercoder/32/790_2.png) [@JimsterCoder](https://community.openems.io/u/JimsterCoder)\
**Post date:** [May 20, 2024, 8:37am UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/3 "2024-05-20T08:37:41Z")

</div>

You example above does not work. “[http://localhost:8084/rest/channel/meter0/ActivePower](http://localhost:8084/rest/channel/meter0/ActivePower)”  
Authentication Failed. See my full question below, please.

I am trying to use the REST-Api controller to get data from my system, as documented here

> **[openems/io.openems.edge.controller.api.rest at develop · OpenEMS/openems](https://github.com/OpenEMS/openems/tree/develop/io.openems.edge.controller.api.rest)**
>
> OpenEMS - Open Source Energy Management System. Contribute to OpenEMS/openems development by creating an account on GitHub.

I am unable to get authentication to work. The documentation mentions using admin or user as passwords but neither work. We do actually have a user authentication system with users/passwords but none of those work either.

The Document says to use the chrome add-on Talend API. If I try the recommended format  
[http://x:user@192.168.1.10:8084/rest/channel/\_sum/EssSoC](http://x:user@192.168.1.10:8084/rest/channel/_sum/EssSoC)  
Talend does nothing, fails… does not send a request at all.

If I remove x:user and send  
[http://192.168.1.10:8084/rest/channel/\_sum/EssSoC](http://192.168.1.10:8084/rest/channel/_sum/EssSoC)  
Talend sends the command and Edge responds  
{“jsonrpc”:“2.0”,“id”:“00000000-0000-0000-0000-000000000000”,“error”:{“code”:1003,“message”:“Authentication failed”,“data”:}}

Using a web browser to send the request  
[http://x:user@192.168.1.10:8084/rest/channel/\_sum/EssSoC](http://x:user@192.168.1.10:8084/rest/channel/_sum/EssSoC)  
gets the same response as above  
{“jsonrpc”:“2.0”,“id”:“00000000-0000-0000-0000-000000000000”,“error”:{“code”:1003,“message”:“Authentication failed”,“data”:}}

In conclusion:  
Talend doesn’t work at all if I put in the x:user

Using a browser sends the command to Edge but authentication fails.

Please, how do I get this to work? How do I authenticate with the REST-Api controller

Thanks,  
James

---

<div class="post-metadata">

**Author:** ![NiallDarwin](https://community.openems.io/user_avatar/community.openems.io/nialldarwin/32/857_2.png) [@NiallDarwin](https://community.openems.io/u/NiallDarwin)\
**Post date:** [May 20, 2024, 9:14am UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/4 "2024-05-20T09:14:16Z")

</div>

I’m not at all technical so these are just guesses, please let me know how far wrong I am.

What does the "x:user " relate to? it kinda looks like a file path but also doesn’t and I don’t think a file path has a place in a command like this.

I believe that the authentication we use is only on the backend whereas the REST API is in edge. So I don’t see that it will be the same authentication system/credentials.

Which leaves me to question:  
\*What authentication is the API looking for?  
\*Where is the API verifying the data for authentication ?  
If we can find that maybe we can begin to understand the issue?

---

<div class="post-metadata">

**Author:** ![Sn0w3y](https://community.openems.io/user_avatar/community.openems.io/sn0w3y/32/636_2.png) [@Sn0w3y](https://community.openems.io/u/Sn0w3y)\
**Post date:** [May 20, 2024, 10:24am UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/5 "2024-05-20T10:24:55Z")

</div>

> [@NiallDarwin](#):
>
> What does the "x:user " relate to?

Auth

> [@NiallDarwin](#):
>
> I believe that the authentication we use is only on the backend whereas the REST API is in edge. So I don’t see that it will be the same authentication system/credentials.

you need to Auth @ the Edge Device locally so x:user is okay

---

<div class="post-metadata">

**Author:** ![JimsterCoder](https://community.openems.io/user_avatar/community.openems.io/jimstercoder/32/790_2.png) [@JimsterCoder](https://community.openems.io/u/JimsterCoder)\
**Post date:** [May 20, 2024, 9:16pm UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/6 "2024-05-20T21:16:48Z")

</div>

x:user does not work, neither does x:admin, also mentioned in the documentation. Can you please tell what will work?

Thanks.

---

<div class="post-metadata">

**Author:** ![dsen](https://community.openems.io/letter_avatar_proxy/v4/letter/d/6de8d8/32.png) [@dsen](https://community.openems.io/u/dsen)\
**Post date:** [May 21, 2024, 11:08am UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/7 "2024-05-21T11:08:20Z")

</div>

Hi,  
You should add an HTTP Basic Auth header with the username and password to your request. The HTTP standard has changed and putting the password and user directly in the URL won’t work anymore.  
Send the request to [http://192.168.1.10:8084/rest/channel/\_sum/EssSoC](http://192.168.1.10:8084/rest/channel/_sum/EssSoC) with the Basic Auth header.

Best

---

<div class="post-metadata">

**Author:** ![SaikeshErramshetty](https://community.openems.io/user_avatar/community.openems.io/saikesherramshetty/32/762_2.png) [@SaikeshErramshetty](https://community.openems.io/u/SaikeshErramshetty)\
**Post date:** [May 24, 2024, 7:53am UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/8 "2024-05-24T07:53:09Z")

</div>

Try this, it will work: [http://admin:admin@127.0.0.1:8084/rest/channel/meter0/ActivePower](http://admin:admin@127.0.0.1:8084/rest/channel/meter0/ActivePower)  
and also I discussed about Rest Api endpoints before, it might be helpful: [Using REST Api to get static info of the devices](https://community.openems.io/t/using-rest-api-to-get-static-info-of-the-devices/1972)

---

<div class="post-metadata">

**Author:** ![JimsterCoder](https://community.openems.io/user_avatar/community.openems.io/jimstercoder/32/790_2.png) [@JimsterCoder](https://community.openems.io/u/JimsterCoder)\
**Post date:** [May 24, 2024, 10:09am UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/9 "2024-05-24T10:09:44Z")

</div>

This: [http://admin:admin@127.0.0.1:8084/rest/channel/meter0/ActivePower](http://admin:admin@127.0.0.1:8084/rest/channel/meter0/ActivePower) will NOT work, as the above poster noted, you can no longer put the username:address in the url. It has to be added as he instructed, such as below.

You have to encode the username:password in Base64 using [Basic Authentication Header Generator](https://www.blitter.se/utils/basic-authentication-header-generator/)  
In this case I encoded x:admin

Then use an api tester (Talend addon to chrome) as below to construct the GET message. (the address of my Edge server is 192.168.2.12)

 ![image](https://community.openems.io/uploads/default/original/2X/7/7547a7e5c82bf3154bcb9d933c2df4d30dca5637.png)

---

<div class="post-metadata">

**Author:** ![JimsterCoder](https://community.openems.io/user_avatar/community.openems.io/jimstercoder/32/790_2.png) [@JimsterCoder](https://community.openems.io/u/JimsterCoder)\
**Post date:** [May 24, 2024, 10:18am UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/10 "2024-05-24T10:18:42Z")

</div>

Additionally, here is some python code I wrote to set a value and read it back. I read it back as the response to the POST gives no indication that it was successful. Also note that “name”: “power” is not documented anywhere I could find. All the channels revealed on the display are Read Only (eg \_PropertyPower). I guessed at the word ‘power’ by looking at the debug example and looking in the code.

I hope this helps someone…

```auto
import requests
from requests.auth import HTTPBasicAuth
import time

url = "http://192.168.2.12:8084"
getEndpoint = "/rest/channel/ctrlFixActivePowerRESTapi/_PropertyPower"
postEndpoint = "/jsonrpc"
auth = HTTPBasicAuth('x', 'admin')
headers = {
'Content-Type': 'application/json'
}

#power in watts
power_W = 12345

print (power_W)

data = {
"method": "updateComponentConfig",
"params": {
"componentId": "ctrlFixActivePowerRESTapi",
"properties": [{
"name": "power",
"value": power_W
}]
}
}

postresponse = requests.post(url+postEndpoint, headers=headers, json=data, auth=auth)
print(postresponse.status_code)
print(postresponse.json())

#need a small delay before sending the next request, this for OEMS to process the power setting request
time.sleep(1)

getresponse = requests.get(url+getEndpoint, auth=auth)
print (getresponse.status_code)
print (getresponse.json())

```

---

<div class="post-metadata">

**Author:** ![Sn0w3y](https://community.openems.io/user_avatar/community.openems.io/sn0w3y/32/636_2.png) [@Sn0w3y](https://community.openems.io/u/Sn0w3y)\
**Post date:** [May 24, 2024, 5:39pm UTC](https://community.openems.io/t/using-rest-apis-in-openems/1625/11 "2024-05-24T17:39:13Z")

</div>

Basically same as here:

> [@Tageswerte abfragen](https://community.openems.io/t/tageswerte-abfragen/403/15):
>
> So wie ich das aktuell verstehe gibt es auch keine Methode “queryHistoricTimeseriesEnergy” die du von außerhalb an den /jsonrpc Endpoint senden kannst, weder im openEMS, noch im FEMS. Siehe hier: Was mir komisch erscheint, ist, dass auch diese Methode " getEdgeConfig" nicht funktioniert… @stefan.feilmeier machen wir da was falsch? import requests import json from requests.auth import HTTPBasicAuth # Basic configuration url = 'http://192.168.178.100:80/jsonrpc' headers = { 'Content-Typ…
