# HTTP binding - set payload/body

**URL:** <https://community.openhab.org/t/http-binding-set-payload-body/130415>\
**Category:** Bindings\
**Tags:** httpbinding\
**Created:** [December 22, 2021, 12:30am UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415 "2021-12-22T00:30:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wars](https://community.openhab.org/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@wars](https://community.openhab.org/u/wars)\
**Post date:** [December 22, 2021, 12:30am UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/1 "2021-12-22T00:30:22Z")

</div>

I have a post request which is working fine in postman and even in a rule with `sendHttpPostRequest`

```auto
val url = "https://api.solarmanpv.com/device/v1.0/currentData?language=en"
val token = "oxoxoxoxox"  
val content = '{"deviceSn": "serialnr"}'
val headers = newHashMap("Authorization" -> "Bearer " + token)
var String request = sendHttpPostRequest(url, "application/json", content, headers, 3000)

```

Now I’m trying to convert this to the http bindng, but I don’t understand where I need to put the _content_ part. (this is the same as _body_ or _payload_, correct?)  
Do I need to put this in the `stateContent` param in the channel?  
If I don’t fill in this param I get

```auto
2021-12-22 01:24:19.451 [WARN] [p.internal.http.HttpResponseListener] - Requesting 'https://api.solarmanpv.com/device/v1.0/currentData?language=en' (method='POST', content='null') failed: 500 null

```

and when I enter my content value, I also get a 500 error

```auto
2021-12-22 01:25:23.974 [WARN] [p.internal.http.HttpResponseListener] - Requesting 'https://api.solarmanpv.com/device/v1.0/currentData?language=en' (method='POST', content='org.eclipse.jetty.client.util.StringContentProvider@75c2a206') failed: 500 null

```

Full thing

```auto
UID: http:url:solarman_currentData
label: Solarman currentData
thingTypeUID: http:url
configuration:
  authMode: BASIC
  headers:
    - Authorization = Bearer oxoxoxoxox
  ignoreSSLErrors: false
  baseURL: https://api.solarmanpv.com/device/v1.0/currentData?language=en
  delay: 0
  stateMethod: POST
  refresh: 30
  commandMethod: GET
  contentType: application/json
  timeout: 3000
  bufferSize: 2048
channels:
  - id: SOC_BAP1
    channelTypeUID: http:string
    label: SoC- Battery Pack 1
    description: ""
    configuration:
      stateContent: "deviceSn=serialnr"

```

What am I missing?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [December 22, 2021, 1:23am UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/2 "2021-12-22T01:23:23Z")

</div>

> [@wars](#):
>
> ```auto
> stateMethod: POST
> refresh: 30
> 
> ```

This is usually used to set up a periodic retrieval of data from some remote service, i.e. to update an OH Item’s state.  
It’s not like your on-demand sendHttpPostRequest,

> [@wars](#):
>
> `commandMethod: GET`

is related to you sending a command to an OH ltem, which triggers the HTTP sending.

You might look here -

> [@HTTP help for a Newbie](https://community.openhab.org/t/http-help-for-a-newbie/116808/4):
>
> Let me share an example. Here is my thing: UID: http:url:e5a14ec3b0 label: Lareira thingTypeUID: http:url configuration: authMode: BASIC ignoreSSLErrors: true baseURL: https://192.168.129.10:8000/recepcion\_datos\_4.cgi delay: 0 stateMethod: POST refresh: 120 commandMethod: POST contentType: text/plain timeout: 3000 bufferSize: 2048 channels: - id: switch channelTypeUID: http:switch label: Switch description: "" configuration: onValue: "1" mode: R…

---

<div class="post-metadata">

**Author:** ![wars](https://community.openhab.org/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@wars](https://community.openhab.org/u/wars)\
**Post date:** [December 22, 2021, 2:02pm UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/3 "2021-12-22T14:02:29Z")

</div>

So are you saying I can’t use the http binding for this purpose?

What does `org.eclipse.jetty.client.util.StringContentProvider@3dd04500` actually mean?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [December 22, 2021, 2:09pm UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/4 "2021-12-22T14:09:54Z")

</div>

> [@wars](#):
>
> So are you saying I can’t use the http binding for this purpose?

No.  
What exactly is your purpose, sending a POST when you command an Item? (Having to guess because you didn’t tell us when your rule version runs.)  
Then you do not want any `stateMethod` or `refresh`, but do need to fix `commandMethod`

> [@wars](#):
>
> What does `org.eclipse.jetty.client.util.StringContentProvider@3dd04500` actually mean?

It’s the unique identity of the little job the binding runs to carry out the requested tasks. In this case I think that’s the “every 30 seconds POST” that you set up.

---

<div class="post-metadata">

**Author:** ![wars](https://community.openhab.org/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@wars](https://community.openhab.org/u/wars)\
**Post date:** [December 22, 2021, 2:34pm UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/5 "2021-12-22T14:34:27Z")

</div>

This post request is actualy grabbing data from my solarpanel cloud. So I wanted to trigger this every 5 minutes (now setup every 30s indeed). This post request returns a json offcourse which I wanted to transform into some items.

I already changed `commandMethod` to `POST`, but same message.

And to be clear, everything works in a rule, but I thought the HTTP binding is more suiteable for this.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [December 22, 2021, 2:41pm UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/6 "2021-12-22T14:41:16Z")

</div>

> [@wars](#):
>
> So I wanted to trigger this every 5 minutes (now setup every 30s indeed). This post request returns a json offcourse which I wanted to transform into some items.

Okay, I did not understand that at all.  
Maybe all you need to do is send valid JSON with your request

> [@wars](#):
>
> `stateContent: "deviceSn=serialnr"`

Needs some quotes in the payload  
`"\"deviceSn\"=\"serialnr\""`

---

<div class="post-metadata">

**Author:** ![wars](https://community.openhab.org/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@wars](https://community.openhab.org/u/wars)\
**Post date:** [December 22, 2021, 2:57pm UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/7 "2021-12-22T14:57:08Z")

</div>

Tried al kind of possibilities, but can’t figure it out. Will stick with my rule or use another approach

---

<div class="post-metadata">

**Author:** ![gresli](https://community.openhab.org/letter_avatar_proxy/v4/letter/g/e9c0ed/32.png) [@gresli](https://community.openhab.org/u/gresli)\
**Post date:** [September 19, 2022, 12:13pm UTC](https://community.openhab.org/t/http-binding-set-payload-body/130415/8 "2022-09-19T12:13:47Z")

</div>

Hi

If I understood right, you want to send a HTTP request with a body part. I did something similar, in my case I sent a PUT request containing a JSON payload.

There is no openHAB transformation that allows to send a HTTP body, you need to create a map. To do so place a file in your transformations folder (usually /etc/openhab/transformations) with the name of your choice and the .map extension. As an example let’s use light.map. Then put some content where you map the command to an output. i.e.:

ON: { LIGHT=1 }  
OFF: { LIGHT=0 }

In the command transformation put the value _MAP:light.map_  
Once your channel gets the command ON, the HTTP call with body _{ LIGHT=1 }_ will be sent to your device. If the command is OFF, the body will contain _{ LIGHT=0 }_
