Ignition - Script - API call error

I have a script with goes as follow. I am trying to print weather data by API. This API end point and the parameters I posted is working fine when I checked with POSTMAN API app. But it doesn't work while I do from the Ignition script.
postParams = {
"lat": 27.2046,
"lon": 77.4977,
"appid": "83a56133d05abc254fe1c9173157793b"
}

url = "https://api.openweathermap.org/data/2.5/weather"
weather_data = system.net.httpPost(url, postParams)
print weather_data

I would like to know basically how does "system.net.httpPost(url, postParams)" work? As the client end point is not available as of now, I use this weather API for testing purpose.

Regards
Elango

When seeking help with something that doesn't work, it may be a good idea to describe what exactly doesn't work. What error are you getting ? Is there anything at all ? etc.

I quickly checked the doc for openweathermap, and I didn't find anything about POST requests. Are you sure that's the correct method ? It seems to accept GET, so try this instead.

Also, use a httpclient:
https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient

The Ignition SCADA is on cloud and it should connect with opto22 RIO over API, not MQTT or OPC UA communication method. it's our client requirement to use only API cmethod for collecting data from opto22 RIO.

As actual API endpoint is not available right now, I am doing a weather and news "API test" to make sure that I will get into the proper script in Ignition side. so, instead of opto22 API endpoints, I am using weather endpoints.

The following scripts' APIs are working fine when I use POSTMAN app for testing, but it gives error while I tested through Ignition Scripting console.

Script in Ignition:

postParams = {
"lat": 27.2046,
"lon": 77.4977,
"appid": "83a56133d05abc254fe1c9173157793b"
}

url = "https://api.openweathermap.org/data/2.5/weather"
weather_data = system.net.httpPost(url, postParams)
print weather_data

Am I using the syntax and format correctly? Is there any http API call
examples to test the API communication?

Console Error:
16:54:30.309 [AWT-EventQueue-0] INFO designer.update-and-save - Save finished in 141ms.
16:54:43.036 [AWT-EventQueue-0] ERROR com.inductiveautomation.ignition.client.util.gui.ErrorUtil - Error executing script for event: mousePressed
on component: Button.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):

Your script is causing an error, we'll need the stacktrace to move forward (the part that you cut at the end of the error message)

Two things I suggest to make your posts more readable:

  1. use code formatting to paste code. 2 solutions:
  • select your code and click this button:
    image
  • wrap your code in triple backticks (```) like this:
    ```
    code
    ```
  1. for walls of text, like stacktraces usually are, you can use the <details> tag, like so:
    <details>
    <summary>quick description</summary> (this line is optional)
    text
    </details>
    which ends up looking like this:
quick description text
3 Likes