# API PUT with JSON

**URL:** <https://discourse.nodered.org/t/api-put-with-json/58455>\
**Category:** General\
**Created:** [16 February 2022 10:47 UTC](https://discourse.nodered.org/t/api-put-with-json/58455 "2022-02-16T10:47:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 10:47 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/1 "2022-02-16T10:47:44Z")

</div>

Hi,

I want to work with API PUT but it's necessary to give a JSON frame with it. How can I do that?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10f7a80bbc22134d4809cacef945c1e4961453c7.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 February 2022 11:23 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/2 "2022-02-16T11:23:52Z")

</div>

> [@Milanovic](#):
>
> API PUT

try switching your http-request node's Method to **PUT** and whatever `msg.payload` you send to it will be the body of the request.

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 12:18 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/3 "2022-02-16T12:18:09Z")

</div>

How can I send that body with it?

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 13:01 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/4 "2022-02-16T13:01:18Z")

</div>

Which node does I need to send the body and where must I place it ?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 February 2022 13:25 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/5 "2022-02-16T13:25:17Z")

</div>

Your question is how to create a `msg.payload` which will be the body of the request ?  
to name a few .. you can use either an Inject, Change or Function node etc

What have you tried ? What is the JSON frame body of the request that you need to send ?

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 13:29 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/6 "2022-02-16T13:29:16Z")

</div>

At this moment I have this script.  
The JSON body is : json={'mode': 'NORMAL',"limit": {"unit": "PERCENTAGE", "value": 100 }}

[{"id":"55a991d4e79c0269","type":"inject","z":"b3be6624e0cc5c82","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":320,"wires":[["f4a8e4d3c14a6659","95460b32b28ead83","ed43323f17b1c448","03514bb389890642","9305a1779c424450","34016018192a8a7b"]]},{"id":"34016018192a8a7b","type":"http request","z":"b3be6624e0cc5c82","name":"Laadpaal sturen","method":"POST","ret":"obj","paytoqs":"body","url":"[https://app1pub.smappee.net/dev/v3/servicelocation/59792/actuator/1/on","tls":"","persist":false,"proxy":"","authType":"bearer","senderr":true,"x":460,"y":360,"wires":[["f905ccdb55bd2d80"]]},{"id":"f905ccdb55bd2d80","type":"debug","z":"b3be6624e0cc5c82","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":280,"wires](https://app1pub.smappee.net/dev/v3/servicelocation/59792/actuator/1/on%22,%22tls%22:%22%22,%22persist%22:false,%22proxy%22:%22%22,%22authType%22:%22bearer%22,%22senderr%22:true,%22x%22:460,%22y%22:360,%22wires%22:%5B%5B%22f905ccdb55bd2d80%22%5D%5D%7D,%7B%22id%22:%22f905ccdb55bd2d80%22,%22type%22:%22debug%22,%22z%22:%22b3be6624e0cc5c82%22,%22name%22:%22%22,%22active%22:true,%22tosidebar%22:true,%22console%22:false,%22tostatus%22:false,%22complete%22:%22payload%22,%22targetType%22:%22msg%22,%22statusVal%22:%22%22,%22statusType%22:%22auto%22,%22x%22:750,%22y%22:280,%22wires)":}]

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 February 2022 13:40 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/7 "2022-02-16T13:40:31Z")

</div>

Your Flow cannot be imported .. use the Preformatted Text icon when you share code  
so it will be correctly formatted on the Forum.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/2689fb7630c04be0c8fd389bb65adcbbb995abca.png)

Try this ..

```auto
[{"id":"55a991d4e79c0269","type":"inject","z":"54efb553244c241f","name":"inject data as Json","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"mode\":\"NORMAL\",\"limit\":{\"unit\":\"PERCENTAGE\",\"value\":100}}","payloadType":"json","x":330,"y":1760,"wires":[["34016018192a8a7b"]]},{"id":"34016018192a8a7b","type":"http request","z":"54efb553244c241f","name":"Laadpaal sturen","method":"POST","ret":"obj","paytoqs":"body","url":"https://app1pub.smappee.net/dev/v3/servicelocation/59792/actuator/1/on","tls":"","persist":false,"proxy":"","authType":"bearer","senderr":true,"x":560,"y":1820,"wires":[["f905ccdb55bd2d80"]]},{"id":"f905ccdb55bd2d80","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":1820,"wires":[]},{"id":"ead31c6b5e54e5bb","type":"inject","z":"54efb553244c241f","name":"inject data as string","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"json={\"mode\": \"NORMAL\",\"limit\": {\"unit\": \"PERCENTAGE\", \"value\": 100 }}","payloadType":"str","x":330,"y":1880,"wires":[["34016018192a8a7b"]]},{"id":"377dc6d019125967","type":"comment","z":"54efb553244c241f","name":"OR","info":"","x":330,"y":1820,"wires":[]}]

```

(note that i changed the single quotes to double quotes for mode and NORMAL because single quotes are not valid Json)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 13:51 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/8 "2022-02-16T13:51:41Z")

</div>

```auto
[{"id":"f905ccdb55bd2d80","type":"debug","z":"b3be6624e0cc5c82","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":280,"wires":[]},{"id":"34016018192a8a7b","type":"http request","z":"b3be6624e0cc5c82","name":"Laadpaal sturen","method":"POST","ret":"obj","paytoqs":"body","url":"https://app1pub.smappee.net/dev/v3/servicelocation/59792/actuator/1/on","tls":"","persist":false,"proxy":"","authType":"bearer","senderr":true,"x":460,"y":360,"wires":[["f905ccdb55bd2d80"]]},{"id":"55a991d4e79c0269","type":"inject","z":"b3be6624e0cc5c82","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":320,"wires":[["f4a8e4d3c14a6659","95460b32b28ead83","ed43323f17b1c448","03514bb389890642","9305a1779c424450","34016018192a8a7b"]]}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 February 2022 13:56 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/9 "2022-02-16T13:56:21Z")

</div>

better 😉

i shared in my last post a Flow for you to try ..  
( From the menu of the Node-red Editor you can select Import (or Ctrl-I) and copy paste to import and test )

By the way .. do you have any online documentation for your API ?

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 14:29 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/10 "2022-02-16T14:29:45Z")

</div>

online documentation:

```auto
[type or paste code here](https://smappee.atlassian.net/wiki/spaces/DEVAPI/overview)

```

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 14:31 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/11 "2022-02-16T14:31:07Z")

</div>

But on this moment I can't send a body with it. That's my problem, I don't know how to send the body (in json) with it

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 February 2022 15:09 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/12 "2022-02-16T15:09:05Z")

</div>

> [@Milanovic](#):
>
> I can't send a body with it

we understand the problem .. this is what we are trying to figure out 😉  
and i explained ways of sending a request body .. by sending your Json as part of the `msg.payload`

1. you didnt tell as if you tried the flow example i sent you in my previous post ?
2. from the documentation, which API method are you trying ? can you send us the exact link instead of the main page ? Is it the one with the Actuator ? [Actuator ON](https://smappee.atlassian.net/wiki/spaces/DEVAPI/pages/526647327/Actuator+ON)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [17 February 2022 13:30 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/13 "2022-02-17T13:30:27Z")

</div>

Yes I tried your example but I receive error 405 even if I try to send it as a string  
the exact link: [https://app1pub.smappee.net/dev/v3/chargingstations/6000000046/connectors/1/mode](https://app1pub.smappee.net/dev/v3/chargingstations/6000000046/connectors/1/mode)  
json body: {"mode":"PAUSED"}

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02e9377069e283b9ce886f00fb15f0d3e154b4ef.png)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [17 February 2022 13:38 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/14 "2022-02-17T13:38:47Z")

</div>

@UnborN I already found my problem, in the example was the method on 'Post' but it must 'Put'.

Thank you for the big help!

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [17 February 2022 14:14 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/15 "2022-02-17T14:14:03Z")

</div>

its important to share with us the correct links to the documentation of the API  
what we needed was this page : [Set the charging mode of one of the connectors of a charging station](https://smappee.atlassian.net/wiki/spaces/DEVAPI/pages/2803367937/Set+the+charging+mode+of+one+of+the+connectors+of+a+charging+station)

im glad it worked 👍

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 April 2022 14:14 UTC](https://discourse.nodered.org/t/api-put-with-json/58455/16 "2022-04-18T14:14:13Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
