# API PUT request

**URL:** <https://discourse.nodered.org/t/api-put-request/11915>\
**Category:** General\
**Created:** [6 June 2019 15:03 UTC](https://discourse.nodered.org/t/api-put-request/11915 "2019-06-06T15:03:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![massi94](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@massi94](https://discourse.nodered.org/u/massi94)\
**Post date:** [6 June 2019 15:03 UTC](https://discourse.nodered.org/t/api-put-request/11915/1 "2019-06-06T15:03:31Z")

</div>

Hello, sorry if this could be a basic/stupid question.

I need to make put and get request using NODE-RED API in order to change something in the flow. While the GET and DELETE works fine, I have some problems with the PUT request. What I'm writing is:  
curl -X PUT -H "Content-Type: application/json" -d'MY\_NEW\_FLOW' URL  
The problem is that I am receiving the correct response (The flow ID) but instead of updating the flow everything is erased. Like if I'm not posting any data at all.

What I'm missing here?  
Sorry for the touble.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 June 2019 15:12 UTC](https://discourse.nodered.org/t/api-put-request/11915/2 "2019-06-06T15:12:52Z")

</div>

You don't say which api you are using. Is it `/flows` or `/flow` ?  
What format is your flow data in?

---

<div class="post-metadata">

**Author:** ![massi94](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@massi94](https://discourse.nodered.org/u/massi94)\
**Post date:** [6 June 2019 15:27 UTC](https://discourse.nodered.org/t/api-put-request/11915/3 "2019-06-06T15:27:30Z")

</div>

I'm making the update using  
`/flow/:id`

as data I'm putting  
`-d'{"id":"9aa2a361.a29db","label":"TEST","info":"","nodes":[{"id":"b52a315e.f2082","type":"inject","z":"9aa2a361.a29db","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":160,"wires":[["ecac16f5.111b48"]]},{"id":"ecac16f5.111b48","type":"debug","z":"9aa2a361.a29db","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":500,"y":200,"wires":[]}]}'`

That is the flow I got with the `curl http://127.0.0.1:1880/flow/9aa2a361.a29db`

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [6 June 2019 16:30 UTC](https://discourse.nodered.org/t/api-put-request/11915/4 "2019-06-06T16:30:36Z")

</div>

> [@massi94](#):
>
> I'm making the update using  
> `/flow/:id`

Just to be clear, the PUT url you are using is actually `http://127.0.0.1:1880/flow/9aa2a361.a29db` with the flow id substituted for the `:id` placeholder, right?

---

<div class="post-metadata">

**Author:** ![massi94](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@massi94](https://discourse.nodered.org/u/massi94)\
**Post date:** [6 June 2019 16:37 UTC](https://discourse.nodered.org/t/api-put-request/11915/5 "2019-06-06T16:37:59Z")

</div>

Yes right

---

<div class="post-metadata">

**Author:** ![massi94](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@massi94](https://discourse.nodered.org/u/massi94)\
**Post date:** [7 June 2019 07:16 UTC](https://discourse.nodered.org/t/api-put-request/11915/6 "2019-06-07T07:16:24Z")

</div>

In order to be a bit more clear.  
This is what I'm doing.

with  
`curl http://localhost:1880/flows` i grab every flow I have at the moment.  
Then i search for the Id I need and with  
`curl http://localhost:1880/flow/9aa2a361.a29db` I double check that the flow grabbed is the right one.  
Then just for testing purpose i grab the flow

`{"id":"9aa2a361.a29db","label":"TEST","info":"","nodes":[{"id":"b52a315e.f2082","type":"inject","z":"9aa2a361.a29db","name":"Pippo","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":220,"wires":[["ecac16f5.111b48"]]},{"id":"ecac16f5.111b48","type":"debug","z":"9aa2a361.a29db","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":260,"wires":[]}]}`

I then tryed sending back the same flow or a new one with the inject name changed from Gigi (original) to another one like Pippo.  
I use this

`curl -X PUT -H "Content-Type: application/json" -d '{"id":"9aa2a361.a29db","label":"TEST","info":"","nodes":[{"id":"b52a315e.f2082","type":"inject","z":"9aa2a361.a29db","name":"Pippo","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":220,"wires":[["ecac16f5.111b48"]]},{"id":"ecac16f5.111b48","type":"debug","z":"9aa2a361.a29db","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":260,"wires":[]}]}' http://localhost:1880/flow/9aa2a361.a29db`

Then I've noticed two things.  
The first is that if i use the `-H "Content-Type: application/json"`  
I get this error

```auto
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token # in JSON at position 0<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at createStrictSyntaxError (c:\Jobs\Dev\Node\node_modules\node-red\node_modules\body-parser\lib\types\json.js:157:10)<br> &nbsp; &nbsp;at parse (c:\Jobs\Dev\Node\node_modules\node-red\node_modules\body-parser\lib\types\json.js:83:15)<br> &nbsp; &nbsp;at c:\Jobs\Dev\Node\node_modules\node-red\node_modules\body-parser\lib\read.js:121:18<br> &nbsp; &nbsp;at invokeCallback (c:\Jobs\Dev\Node\node_modules\node-red\node_modules\raw-body\index.js:224:16)<br> &nbsp; &nbsp;at done (c:\Jobs\Dev\Node\node_modules\node-red\node_modules\raw-body\index.js:213:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (c:\Jobs\Dev\Node\node_modules\node-red\node_modules\raw-body\index.js:273:7)<br> &nbsp; &nbsp;at emitNone (events.js:106:13)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:208:7)<br> &nbsp; &nbsp;at endReadableNT (_stream_readable.js:1056:12)</pre>
</body>
</html>

```

If I don't use the `-H "Content-Type: application/json"` part, I get the right resposnse as shown in the documentation with the response being the id of the flow: `{"id":"9aa2a361.a29db"}`  
Then the node red flow updates and ask me to check before merging. Then what I see is that everything is deleted, like if I'm leaving blank the -d''.

I don't know if I'm missing something. Is the first time I got a problem like that

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [10 June 2019 17:34 UTC](https://discourse.nodered.org/t/api-put-request/11915/7 "2019-06-10T17:34:16Z")

</div>

You didn't mention which server type or OS you are on, but I suspect that JSON syntax is being mangled by your shell's command line processing (specifically, "globbing") -- for example, certain shells/cli options expand curly braces to locate matching filenames.

You might try to use the `curl --globoff ...` option to disable globbing, or even the --data-raw argument. But first I would PUT the data to an `http in` endpoint node linked to a `debug` node set to "show the complete msg object", where I could see everything that is being passed in by the curl command.
