# system.net.httpGet errors

**URL:** <https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771>\
**Category:** Ignition\
**Created:** [May 7, 2019, 9:47pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771 "2019-05-07T21:47:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RForshey](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@RForshey](https://forum.inductiveautomation.com/u/RForshey)\
**Post date:** [May 7, 2019, 9:47pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771/1 "2019-05-07T21:47:52Z")

</div>

I’ve got to retrieve information from a REST API. If I run this query in ARC, I get the information and the world is an awesome place:

[http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=001000017359&token=cfapiKnJ4Td2WQ8hf](http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=001000017359&token=cfapiKnJ4Td2WQ8hf)

My “attempt” at writing the script is:

```auto
response = system.net.httpGet('http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=001000018898')
token = cfapiKnJ4Td2WQ8hf
data = system.util.jsonDecode(response)
print data

```

I get a “401” error. I can program the heck out of PLCs, but this scripting stuff is killing me. Any ideas?

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 7, 2019, 9:54pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771/2 "2019-05-07T21:54:15Z")

</div>

You aren’t passing the token in as far as I can see, which is why you’re getting 401 Unauthorized.

---

<div class="post-metadata">

**Author:** ![RForshey](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@RForshey](https://forum.inductiveautomation.com/u/RForshey)\
**Post date:** [May 7, 2019, 9:55pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771/3 "2019-05-07T21:55:28Z")

</div>

Great news! Uh… how do I pass the token?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 7, 2019, 10:11pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771/4 "2019-05-07T22:11:36Z")

</div>

> [@RForshey](#):
>
> ```auto
> response = system.net.httpGet('http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=001000018898')
> token = <token>
> data = system.util.jsonDecode(response)
> print data
> 
> ```

You're defining `token` out as a variable, not adding it to the URL. The API you're talking to appears to just want the token as a URL parameter, so you can just add it to the URL like you have in your example URL:

```auto
response = system.net.httpGet('http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=001000018898&token=<token>')

```

If you want to make it more dynamic, you can use Python's string manipulation...in technically, quite a few different ways:

```python
#standard string interpolation, works basically everwhere
print "http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=%s&token=%s" % ("001000018898", "token")

# only in Ignition 8.0.0+:
#print "http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order={0}&token={1}".format("001000018898", "token")
#args = {"sales-order": "001000018898", "token": "token"}
#print "http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order={sales-order}&token={token}".format(**args)

#or, using a standard library function: 
from urllib import urlencode
args = {"sales-order": "001000018898", "token": "token"}
print "http://devapp1:8080/cellfusion/api/v1/orders/details?" + urlencode(args)

```

---

<div class="post-metadata">

**Author:** ![RForshey](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@RForshey](https://forum.inductiveautomation.com/u/RForshey)\
**Post date:** [May 7, 2019, 10:22pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771/5 "2019-05-07T22:22:24Z")

</div>

Outstanding! This:

response = system.net.httpGet(‘[http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=001000018898&token=cfapiKnJ4Td2WQ8hf](http://devapp1:8080/cellfusion/api/v1/orders/details?sales-order=001000018898&token=cfapiKnJ4Td2WQ8hf)’)  
data = system.util.jsonDecode(response)  
print data

retrieved the expected results. How do I expose the data in a table or?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 7, 2019, 10:59pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771/6 "2019-05-07T22:59:47Z")

</div>

> [@RForshey](#):
>
> retrieved the expected results. How do I expose the data in a table or?

Easy answer: Use Perspective, because the table component natively accepts JSON data, and there's also an HTTP binding type.

Harder answer: If you're using Vision, or just want to translate this into a dataset somehow, then you will need to decide how to map your JSON structure to a dataset.  
[`system.dataset.toDataSet()`](https://docs.inductiveautomation.com/display/DOC80/system.dataset.toDataSet) takes two arguments - a string "array" (technically, a Python list) of column names, and then a 2D (nested) "array" of data objects. Something like this - you'll have to manipulate your JSON object (which `system.util.jsonDecode` should give you as a Python datastructure):

```python
headers = ["city", "state", "population"]

data = [
	["New York", "New York", "7000000"], #row 1
	["Los Angeles", "California", "8000000"], #row 2
	["Podunk", "Alaska", "8"] #row 3
]

dataset = system.dataset.toDataSet(headers, data)

```

---

<div class="post-metadata">

**Author:** ![RForshey](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@RForshey](https://forum.inductiveautomation.com/u/RForshey)\
**Post date:** [May 7, 2019, 11:06pm UTC](https://forum.inductiveautomation.com/t/system-net-httpget-errors/24771/7 "2019-05-07T23:06:59Z")

</div>

Thanks so much for all your help. I’ve been trying to get this to work for a couple days, even submitted a help desk ticket. You’ve solved my basic issues.
