# Read data from API using Ignition Project Library

**URL:** <https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450>\
**Category:** Ignition\
**Created:** [June 27, 2024, 10:39am UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450 "2024-06-27T10:39:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soundararajans\_S](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@Soundararajans\_S](https://forum.inductiveautomation.com/u/Soundararajans_S)\
**Post date:** [June 27, 2024, 10:39am UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/1 "2024-06-27T10:39:31Z")

</div>

Hi,

Am trying to get data from API url. In this API URL I have to pass payload also. When am trying to send request am getting below reply only.

{  
"Data": ,  
"Message": "No data Available",  
"Status": "InputError"  
}

When am using the same URL with payload it's working in Postman application.

Note:  
In this API we are not using parameters to pass.

 ![Screenshot 2024-06-27 160700](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/c/bc5ebb3e003a843d0d17657ca69b28379108f2df.png)  
 ![Screenshot 2024-06-27 160907](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/1681ef15d521c9b80d99b4fc26d0ad6e78ee0db0.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 27, 2024, 1:00pm UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/2 "2024-06-27T13:00:47Z")

</div>

I would recommend using [system.net.httpClient | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-net/system-net-httpClient)

Example script at the bottom (replace `get` with `post`)

```python
# Create the JythonHttpClient.
client = system.net.httpClient()
 
# Sent a GET request.
response = client.get("https://httpbin.org/get", params={"a": 1, "b": 2})
 
# Validate the response.
if response.good:
    # Do something with the response
    print response.json['args']['a']

```

Read through the whole documentation - note this part at the top

> Be aware that httpClient instances are heavyweight, so they should be created sparingly and reused as much as possible. For ease of reuse, consider instantiating a new httpClient as a top-level variable in a project library script.

---

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [June 27, 2024, 6:21pm UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/3 "2024-06-27T18:21:51Z")

</div>

I would also pay attention to the _type_ of http request you're making.

In your Script Console example, you're using [`system.net.httpPost`](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-net/system-net-httpPost), but in Postman, you're using a `GET` request. `POST` and `GET` are almost always routed differently in an API. **`GET`** is used for **reading** data, and **`POST`** is used for **writing** data (by convention).

Try using the [`system.net.httpGet`](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-net/system-net-httpGet) method instead. That might work for you.

---

<div class="post-metadata">

**Author:** ![Soundararajans\_S](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@Soundararajans\_S](https://forum.inductiveautomation.com/u/Soundararajans_S)\
**Post date:** [June 28, 2024, 3:31am UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/4 "2024-06-28T03:31:55Z")

</div>

@Brandon_Peterson Both are tried. Even it's not working.

There is a small difference is there in API parameter passing. Here am using payload / body parameters in API.

If using no payload API working fine. When am using payload parameter only am facing issue.

---

<div class="post-metadata">

**Author:** ![Soundararajans\_S](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@Soundararajans\_S](https://forum.inductiveautomation.com/u/Soundararajans_S)\
**Post date:** [June 28, 2024, 3:36am UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/5 "2024-06-28T03:36:13Z")

</div>

@bkarabinchak.psi Same problem. httpPost and httpClient both are showing same kind of problem only.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 28, 2024, 5:52am UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/6 "2024-06-28T05:52:08Z")

</div>

Your screenshot with the script console shows that the API is returning something. It's returning json with some infos in it, and particularly that you have an input error.  
If the parameters look like the ones in postman, maybe there's a type issue somewhere, or some formatting error.

---

<div class="post-metadata">

**Author:** ![Soundararajans\_S](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@Soundararajans\_S](https://forum.inductiveautomation.com/u/Soundararajans_S)\
**Post date:** [June 28, 2024, 8:57am UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/7 "2024-06-28T08:57:35Z")

</div>

Hi,

Below code is working fine. Here we are passing parameter in json format and getting json data.

'''  
import json  
from [system.net](http://system.net) import httpClient

url = "[http://192.168.0.1/server/api/order\_pending](http://192.168.0.1/server/api/order_pending)"  
payload = {  
"ORG\_ID": "xx",  
"DEPARTMENT": "yyyyy",  
"RESOURCE": "zzzzz"  
}

payload\_json = json.dumps(payload)

client = httpClient()  
response = client.post(url, data=payload\_json)

print("Response Text:")  
print(response.getText())  
'''

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 28, 2024, 12:37pm UTC](https://forum.inductiveautomation.com/t/read-data-from-api-using-ignition-project-library/92450/8 "2024-06-28T12:37:46Z")

</div>

Did you see what @Brandon_Peterson pointed out? You are doing a `GET` request in your postman picture but you're doing a `POST` in your script.

My guess is you need to do it with a `GET` (and perhaps use params instead of data). Also, don't convert to json first. Read the docs I sent you -

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4e371432980ea0adffc86117dd562a8ca3558d85.png)

The function itself encodes the dictionary to JSON. It expects a dictionary as one of the acceptable datatypes. If you give it JSON directly - that may be messing with things.
