# HTTP Error 201 on successful POST API

**URL:** <https://forum.inductiveautomation.com/t/http-error-201-on-successful-post-api/13971>\
**Category:** Ignition\
**Created:** [April 3, 2017, 3:12am UTC](https://forum.inductiveautomation.com/t/http-error-201-on-successful-post-api/13971 "2017-04-03T03:12:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [April 3, 2017, 3:12am UTC](https://forum.inductiveautomation.com/t/http-error-201-on-successful-post-api/13971/1 "2017-04-03T03:12:47Z")

</div>

I have written some GET API’s that work ok using the python library ‘urllib2’.  
I’ve just written a POST API, and it is returning HTTP Status 201: Created.  
After doing some reading, it seems any HTTP 200 status means the request was successful. So why am i getting an error thrown in Ignition?  
As far as i can tell, the request was successful. I created a new item on the server end as expected.

Should I write some “try: except” code to ignore it? I don’t really want to do that without understanding why it is making an error.

Sorry I’m not hugely familiar with the HTTP web space.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/832f907afd18673286d63c7f7dcfb36a6e9ced81.PNG)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 3, 2017, 11:38am UTC](https://forum.inductiveautomation.com/t/http-error-201-on-successful-post-api/13971/2 "2017-04-03T11:38:12Z")

</div>

Because urllib2 is stupid. All 2xx responses are success codes, but they are not normally returned by simple web servers.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 3, 2017, 7:35pm UTC](https://forum.inductiveautomation.com/t/http-error-201-on-successful-post-api/13971/3 "2017-04-03T19:35:59Z")

</div>

You might try using the [system.net](http://system.net) HTTP functions or Java’s HTTPUrlConnection directly.

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [April 4, 2017, 2:41am UTC](https://forum.inductiveautomation.com/t/http-error-201-on-successful-post-api/13971/4 "2017-04-04T02:41:49Z")

</div>

Hmmm… right. I’ve managed to find some interesting material online about urllib2’s failures to handle 20X success codes. I guess I might have to just handle it manually.

Edit: I managed to get my POST api working by using the system.net.httpPost() function, with no error thrown on HTTP status 201!! ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:")

Although it took a bit of fiddling with the parameters to get it to work.  
Not sure why this code produced a “Bad Request”: `response=system.net.httpPost(requestUrl, data_dict, headerValues=urlHeader)`  
Yet switching ‘postParams’ for ‘postData’ and doing this succeeded: `data=system.util.jsonEncode(data_dict)
response=system.net.httpPost(url=requestUrl, contentType="application/json", postData=data, headerValues=urlHeader)`  
Where ‘data\_dict’ is a pyDict.
