# Not able to get system.net.httpPost to work correctly

**URL:** <https://forum.inductiveautomation.com/t/not-able-to-get-system-net-httppost-to-work-correctly/71179>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 16, 2023, 7:12pm UTC](https://forum.inductiveautomation.com/t/not-able-to-get-system-net-httppost-to-work-correctly/71179 "2023-03-16T19:12:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [March 16, 2023, 7:12pm UTC](https://forum.inductiveautomation.com/t/not-able-to-get-system-net-httppost-to-work-correctly/71179/1 "2023-03-16T19:12:29Z")

</div>

Any help would be appreciated as this API is a pain.

```auto
def runAction(self):
	
	client = system.net.httpClient
	body = "{\r\n \"USERNAME\":\"<uname>\",\r\n \"PASSWORD\":\"<passwrd>\",\r\n \"CLIENT_ID\":\"<Client ID>\"\r\n}"
	
	response = client.post("api.megamation.com/clm/DL/login", headerValues="application/json", bypassCertValidation=True, postData=body)
	decode = system.util.jsonDecode(response)
	
	system.perspective.print(decode)

```

I jsut get python errors within the designer and can't seem to get past this.

Thanks

---

<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:** [March 16, 2023, 7:35pm UTC](https://forum.inductiveautomation.com/t/not-able-to-get-system-net-httppost-to-work-correctly/71179/2 "2023-03-16T19:35:37Z")

</div>

At least part of the issue is that all of the named parameters you're passing into `post` are named incorrectly. Maybe you were looking at the docs for the legacy `httpPost` function? The docs for `httpClient` are here: [system.net.httpClient - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient)

You'd want to look under the JythonHttpClient Methods section as well.

Your body JSON is a bit of a mess too. Might be easier to just pass a dictionary object, but you've gotta fix the other problems first.

edit: and the very first line is wrong too, it should be a method call:

```auto
client = system.net.httpClient()

```

---

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [March 17, 2023, 10:54am UTC](https://forum.inductiveautomation.com/t/not-able-to-get-system-net-httppost-to-work-correctly/71179/3 "2023-03-17T10:54:07Z")

</div>

> Blockquote Might be easier to just pass a dictionary object, but you've gotta fix the other problems first.

How do I do that? The BODY of the POst message is supposed to be in json, which is the coding of the post message. This was taken directly from the API publisher for python.http

---

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [March 17, 2023, 11:08am UTC](https://forum.inductiveautomation.com/t/not-able-to-get-system-net-httppost-to-work-correctly/71179/4 "2023-03-17T11:08:21Z")

</div>

I figured out how this system does dictionary, so I am good there, so I am now getting a response at least.

Only problem is the error that the response isn't json? but it is?

`inductiveautomation.ignition.common.script.JythonExecException Traceback (most recent call last): File "<function:runAction>", line 7, in runAction TypeError: jsonDecode(): 1st arg can't be coerced to String`

---

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [March 17, 2023, 11:38am UTC](https://forum.inductiveautomation.com/t/not-able-to-get-system-net-httppost-to-work-correctly/71179/5 "2023-03-17T11:38:10Z")

</div>

I was able to get it. I will post my final code for anyone else.

```auto
	client = system.net.httpClient()
	body = {"USERNAME":"<uname>", "PASSWORD":"<pass>", "CLIENT_ID":"<client_id>"}
	
	response = client.post("https://api.megamation.com/clm/DL/login", headers={"Content-Type":"application/json"}, data=body)
	res_body = response.getJson(response)
	self.session.custom.api_login = res_body

```
