# Please help: can't post JSON data to emoncms

**URL:** <https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865>\
**Category:** Getting Started\
**Created:** [22 January 2017 21:42 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865 "2017-01-22T21:42:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SilverNodashi](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/2acd7d/32.png) [@SilverNodashi](https://community.openenergymonitor.org/u/SilverNodashi)\
**Post date:** [22 January 2017 21:42 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/1 "2017-01-22T21:42:09Z")

</div>

Hi,

Please, can someone help me?

I’m trying to upload some DS18B20 temperature data to emoncms but the JSON string generate is incorrect, as follows:

```
https://emoncms.org/input/post.json=%7BBed1:?24.6%7D&apikey=429xxxxxxxxxxxxxxxxxxx1c52cd609

```

It should have looked lik this, instead:

```
    https://emoncms.org/input/post.json={Bed1:?24.6}&apikey=429xxxxxxxxxxxxxxxxxxx1c52cd609

```

So, essentially the curly braces are being replaced in the Python code. I do understand why: those are used by Python for other operations. But I don’t know how to fix it? I did try some google searches for an answer but couldn’t find any.

How do I format my URL’s to be compliant with the emoncms API? i.e; [Emoncms - site api](https://emoncms.org/site/api#input)

```
   r = requests.post("https://emoncms.org/input/post.json={Bed1:", params=str(myTempCase) + "}&apikey="+APIKEY)
  print(r.url)
  r.status_code == requests.codes.ok
  print(r.status_code)
```

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [23 January 2017 20:53 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/2 "2017-01-23T20:53:32Z")

</div>

This should help (not used it in a while). [Quickstart — Requests 2.26.0 documentation](http://docs.python-requests.org/en/master/user/quickstart/)

---

<div class="post-metadata">

**Author:** ![pb66](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/pb66/32/27_2.png) [@pb66](https://community.openenergymonitor.org/u/pb66)\
**Post date:** [24 January 2017 01:06 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/3 "2017-01-24T01:06:46Z")

</div>

I’m not entirely sure POST requests are supported at [emoncms.org](http://emoncms.org), you could try using a GET request like this

```auto
r = requests.get(https://emoncms.org/input/post.json?node=1&json={Bed1:24.6}&apikey=429xxxxxxxxxxxxxxxxxxx1c52cd609)

```

(note I have added a node id too)

or there is further POST api documentation on the local emoncms installs at a similar url, which can also be viewed in the source code on the github repo

> <https://github.com/emoncms/emoncms/blob/master/Modules/input/Views/input_api.php#L57-L67>

---

<div class="post-metadata">

**Author:** ![SilverNodashi](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/2acd7d/32.png) [@SilverNodashi](https://community.openenergymonitor.org/u/SilverNodashi)\
**Post date:** [24 January 2017 05:33 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/4 "2017-01-24T05:33:58Z")

</div>

Hi Brian,

Thanx, but I honestly don’t know what to look for in that manual you gave me?

The problem lies with the curley braces - i.e. the **{** and **}** Python uses the curly braces as part of it’s own structure, and [emoncms.org](http://emoncms.org) expects is as part of the URL.  
The other URL options doesn’t allow me to post directly to a given feed

So, the question is, how do I pass a curly brace to my URL structure, without Python thinking it should perform some form of regex call?

i.e. in PHP when you want to “escape” certain characters, you put a forward slash in front of it, but that doesn’t work in Python.

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [24 January 2017 08:32 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/5 "2017-01-24T08:32:21Z")

</div>

I thought the example was straight forward (works for post as well). I know, using a GET is counter intuative 🙂

```python
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.get('http://httpbin.org/get', params=payload)

```

for

```auto
http://httpbin.org/get?key2=value2&key1=value1

```

Your construct is not correct (the url part should end after ‘post.json’), and then construct the data part.

> [@SilverNodashi](#):
>
> ```auto
> r = requests.post("https://emoncms.org/input/post.json={Bed1:", params=str(myTempCase) + "}&apikey="+APIKEY)
> 
> ```

Long time since I last used it though…

---

<div class="post-metadata">

**Author:** ![pb66](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/pb66/32/27_2.png) [@pb66](https://community.openenergymonitor.org/u/pb66)\
**Post date:** [24 January 2017 12:18 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/6 "2017-01-24T12:18:16Z")

</div>

A `requests.post` expects 2 args, the first is a url and the second is the payload in the form of a python dict (dictionary), this is where the curly braces are used.

```auto
payload = {'key1': 'value1', 'key2': 'value2'}

```

As Brian points out your construct is incorrect, you have part of a url containing one curly brace as the first arg and then pass a single value concatenated with the remainder of the url as a string, as the second in place of the dict.

A python dict is very similar to JSON and you’re supposed to pass the dict (JSON?) as an object into the `requests.post` in the form `params = payload` where payload is a JSON like object, not a string representation wrapped in curly braces.

You must include the apikey and node id as part of the url as a near complete api call, only the actual key:value data pairs will be placed in the “payload”.

> [@SilverNodashi](#):
>
> So, the question is, how do I pass a curly brace to my URL structure, without Python thinking it should perform some form of regex call?

You don’t pass the braces to a `requests.post`, but you should be able to pass them to a `requests.get` as that expects a single arg in the form of a complete url containing the JSON string which would include the curly braces.

> [@SilverNodashi](#):
>
> The other URL options doesn’t allow me to post directly to a given feed

None of the input api calls will allow you to post direct to a _feed_. that would require a feed api call, you do not need to use a POST to post data direct to an _input_, “counter intuitive” as Brian says but pretty much the norm around here.

I have had a peek at the code and it does look like POST is implemented on [emoncms.org](http://emoncms.org) despite the absence of documentation on the input api docs page so you should be able to use POST, but GET may be easier.

---

<div class="post-metadata">

**Author:** ![Bill.Thomson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/bill.thomson/32/1834_2.png) [@Bill.Thomson](https://community.openenergymonitor.org/u/Bill.Thomson)\
**Post date:** [24 January 2017 16:35 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/7 "2017-01-24T16:35:57Z")

</div>

> [@SilverNodashi](#):
>
> in PHP when you want to “escape” certain characters, you put a forward slash in front of it

The PHP escape character is a _backslash_ i.e. \ not /  
Ref: [PHP: Escape sequences - Manual](http://php.net/manual/en/regexp.reference.escape.php)

---

<div class="post-metadata">

**Author:** ![SilverNodashi](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/2acd7d/32.png) [@SilverNodashi](https://community.openenergymonitor.org/u/SilverNodashi)\
**Post date:** [25 January 2017 20:19 UTC](https://community.openenergymonitor.org/t/please-help-cant-post-json-data-to-emoncms/2865/8 "2017-01-25T20:19:35Z")

</div>

Thanx borpin. I understand what you’re saying, but how do I get the format expect on [Emoncms - site api](https://emoncms.org/site/api#input)?

 ![](https://community.openenergymonitor.org/uploads/default/original/2X/3/3cd87e7f1cb9e04d8205f427b62e2e0d83563996.jpg)
