# HTTP GET request scripting

**URL:** <https://forum.inductiveautomation.com/t/http-get-request-scripting/12324>\
**Category:** Ignition\
**Created:** [November 2, 2016, 9:19pm UTC](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324 "2016-11-02T21:19:15Z")\
**Posts on this page:** 6\
**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:** [November 2, 2016, 9:19pm UTC](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324/1 "2016-11-02T21:19:15Z")

</div>

Hi all,

I’m once again pushing my Ignition knowledge limits trying to do HTTP requests via an API for an external website.

I have found the resource on Ignition function system.net.httpGet: [https://docs.inductiveautomation.com/display/DOC/system.net.httpGet](https://docs.inductiveautomation.com/display/DOC/system.net.httpGet)

And that put me in the right direction, but I’m still not sure how to properly handle the result data.  
If the server returns an HTTP error status code, how can i extract that and log the appropriate error message?

My code so far:

[code]  
import system

# Generate URL for API call to read products

url = “[https://inventory.dearsystems.com/ExternalApi/Products?Page=1&Limit=100&Name=Log](https://inventory.dearsystems.com/ExternalApi/Products?Page=1&Limit=100&Name=Log)”

# Create header with information required by API

header = {“Content-type”:“application/json”, “api-auth-accountid”:“XXXX-XXXX”, “api-auth-applicationkey:”:“XXXX-XXXX”}

try:  
source = system.net.httpGet(url,’’ ,’’ ,’’,’’,header)  
print source  
except:  
print(“Error calling DEAR API”)[/code]

I don’t think i have quite set up the headers correctly, the reference document for the API i’m trying to call is in PHP, and i have no experience in PHP so might be misinterpreting it.  
This is the example given to connect to the API: [http://support.dearsystems.com/support/solutions/articles/1000054245-connecting-to-the-api](http://support.dearsystems.com/support/solutions/articles/1000054245-connecting-to-the-api)

Any help on creating an http request and dealing with the returned data would be much appreciated.

---

<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:** [November 6, 2016, 7:32pm UTC](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324/2 "2016-11-06T19:32:17Z")

</div>

Solved using the following code:

[code]import system  
import urllib2

# Generate URL for API call to read products

url = “[https://inventory.dearsystems.com/ExternalApi/Products?Page=1&Limit=100&Name=Log](https://inventory.dearsystems.com/ExternalApi/Products?Page=1&Limit=100&Name=Log)”

# Create header with information required by API

urlHeader = {“Content-Type”: “application/json”, “api-auth-accountid”: “XXXXX”, “api-auth-applicationkey”: “XXXXX”}

request = urllib2.Request(url, headers=urlHeader)  
contents = urllib2.urlopen(request).read()

data = system.util.jsonDecode(contents)[/code]

---

<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 10, 2017, 8:56pm UTC](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324/3 "2017-04-10T20:56:25Z")

</div>

Just as a note if anyone comes to this for API help, it is probably better to use Ignitions function **system.net.httpGet()** instead of **urllib2.**  
I have had less issues this way.

---

<div class="post-metadata">

**Author:** ![min.wang](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@min.wang](https://forum.inductiveautomation.com/u/min.wang)\
**Post date:** [February 14, 2018, 7:08am UTC](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324/4 "2018-02-14T07:08:09Z")

</div>

Hello,

I’m new to Ignition. Can you please tell me how to install requests module to Ignition? Currently, when I import requests in the script console. I got the error message: no requests module found.

Many thanks!

Min

---

<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:** [February 14, 2018, 9:51am UTC](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324/5 "2018-02-14T09:51:01Z")

</div>

Hi,

Download requests module from here: [https://pypi.python.org/pypi/requests/0.2.4](https://pypi.python.org/pypi/requests/0.2.4)  
Copy to your ignition server and extract files.  
Install by following these instructions: [https://support.inductiveautomation.com/index.php?/Knowledgebase/Article/View/98/0/importing-and-using-3rd-party-python-libraries-in-ignition](https://support.inductiveautomation.com/index.php?/Knowledgebase/Article/View/98/0/importing-and-using-3rd-party-python-libraries-in-ignition)

---

<div class="post-metadata">

**Author:** ![min.wang](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@min.wang](https://forum.inductiveautomation.com/u/min.wang)\
**Post date:** [February 15, 2018, 12:28am UTC](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324/6 "2018-02-15T00:28:17Z")

</div>

Thank you very much, Richard

Many thanks

Min
