Accessing web services from Ignition

I have a project where I need to retrieve data using web services. Is there any tutorial/sample code available on how to configure Ignition to call web services?
Thanks

inductiveautomation.com/supp … /ignition/
There is a new section on web services. Also they are not all the same.
A service that uses true wsdl dialog is different than an xml server

Also check out
w3schools.com/webservices/default.asp

This
fedorahosted.org/suds/ is the native libraries in ignition

Here are direct links to the sections in the user manual:
inductiveautomation.com/supp … uments.htm
inductiveautomation.com/supp … uments.htm
inductiveautomation.com/supp … esults.htm

Also, the link that @tailfire posted to the SUDS documentation is very helpful.

Thanks for the info
The webservice that I would like to interface with from Ignition uses REST/JSon. I am not too familar with this. I would like to know if we can use Ignition to retrieve data from these type of web services.

The JSON library for python is external, which mean that for now it can’t be used from within Ignition. You’ll be able to get the JSON response back from the server’s RESTful API, but you won’t really be able to do anything useful with it.

Ignition now has built-in JSON parsing functions that convert JSON into Python data structures or parse Python data structures to JSON.

system.util.jsonDecode(jsonString)
system.util.jsonEncode(pyObj)

You can use system.net.httpGet and system.net.httpPost to use RESTful web services.

yes is it can use REST/JSON we are doing it this way as of now

I also need to use webservices. I see is Webservices module in python but I was unable to find any documentation on how to use it.
Thanks for your help

Since 2013, things have improved a lot in the core Ignition product. For all REST (and, really, most HTTP related calls) I’d recommend system.net.httpClient.

1 Like

Thanks. I tried a simple script on sript console and I am getting error
Script
url= 'http://myurl'
client = system.net.httpClient()
response = client.post(url, params = {"DeviceId": "WPISC2001","CardId": "00.00.00.00.44.C0.56.51"})

Error
Traceback (most recent call last):
File "", line 2, in
AttributeError: 'com.inductiveautomation.ignition.designer.gui.tool' object has no attribute 'httpClient'

What version of Ignition are you using?

I am using 7.9.12
Thanks

system.net.httpClient wasn’t available until something like 8.0.6.

You’ll have to stick to system.net.httpGet and system.net.httpPost.

If I use system.net.httpClient is get error code 500 from server. I tried postman and SOAP to confirm the hearder and te url endpoint are working fine. Here is te script I am testing on script console
Script:
url= “my url”
devi =“WPISC2001”
card = “00.00.00.00.44.C0.56.51”
header = {“DeviceId”:devi,“CardId”:card}
print(header)

response = system.net.httpPost(url,‘application/json; charset=utf-8’, headerValues=header)
print(response)

Error:
File “”, line 7, in
IOError: Server returned HTTP response code: 500 for URL: “my url”

You’re sending DeviceId and CardId as header values, not the actual data payload - is that intentional? If so, it’s one of the weirdest web APIs I’ve ever heard of. I would expect you to have to do something like this:

url= 'my url'
devi = 'WPISC2001'
card = '00.00.00.00.44.C0.56.51'
payload = {'DeviceId': devi, 'CardId': card}
print(payload)

response = system.net.httpPost(url, contentType='application/json; charset=utf-8', postData=system.util.jsonEncode(payload))
print(response)

Or, better, with httpClient:

url= 'my url'
devi = 'WPISC2001'
card = '00.00.00.00.44.C0.56.51'
payload = {'DeviceId': devi, 'CardId': card}
print(payload)

response = system.net.httpClient().post(url, payload)
print(response)

Which will automatically encode the payload as JSON and set the content-type header for you.

Thanks a lot PGriffith and everyone. No it was not intentional I made a mistake. I tried your way and it is working now.
Really appreciate your help

Regards
Noveel

1 Like