Feedback after using POST service

Greetings.

Is there any way to verify the HTTP POST action being carried out?

url = “http://some-api-url.com/api
file = “path/to/some/file”
system.net.httpClient().postAsync(url, file=file)

For example, right after the above scripting being executed, is there any way to receive the feedback (like the command being executed)?

postAsync returns a Promise object which you can add a callback to. See https://docs.inductiveautomation.com/display/DOC80/system.net.httpClient

If you want to use the result immediately you should probably just use the blocking variant (post).

Using the normal post method like below, is there a way to get the HTTP response code from the reply?

page = system.net.httpPost(url, {‘x-aio-key’: aioKey, ‘value’:value})

for example when using python requets, “page.status_code” would give you the HTTP code.

Thanks,

Nick

Unfortunately no. Shortcomings like this are one of the things the new system.net.httpClient API fixes.

Going back to the classic system.net.httpPost() function is not what Kevin was suggesting. Use the .post() method of httpClient–its response object has a .statusCode property.

{ As documented in the link Kevin provided. }

@pturmel @Kevin.Herron

Thanks for your advice, it works brilliantly! I just put a quick example snapshot up in case it can be a helpful reference for anyone else.

1 Like

@Kevin.Herron @nicholas.robinson @pturmel

Thanks for the reply!!! I was away from my laptop for a few days didn’t expect the suggestion to come out so fast. Let me look into this now. Thanks all. Have a nice day and take care.

Hi all, I manage to solve this matter after email to the support team and try it on myself. Attached below is the solution:

Inductive Automation has a knowledge base article on how to you can import python modules.
https://support.inductiveautomation.com/index.php?/Knowledgebase/Article/View/98/2/importing-and-using-3rd-party-python-libraries-in-ignition#:~:text=To%20import%20the%20library%20into,located%20inside%20the%20installation%20directory.&text=Now%20you%20are%20ready%20to,of%20your%20newly%20imported%20library!

You can download the official python 2.7 version of the requests module from this website: https://pypi.org/project/requests/#files

You would need to transfer over the “requests”, “idna”, “certifi”, “chardet”, and “urllib3” folders to the “mylib” Ignition folder to use the requests module.

Once this is completed, you’ll be able to use the python requests module to use the post() method within your scripts and the script console of the Designer.

Below is the script to do so

import requests

headers = {
‘x-api-key’: ’ ',
‘Content-Type’: ‘application/json’,
}

data = ‘{“Destination”: " ", “Message”: " ", “Priority”: }’

response = requests.post(‘URL’, headers=headers, data=data, verify=False, auth=(‘username’, ‘password’))

print(response.status_code)