# Posting a Query from Ignition to Cloud using REST API with Auth

**URL:** <https://forum.inductiveautomation.com/t/posting-a-query-from-ignition-to-cloud-using-rest-api-with-auth/63141>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 18, 2022, 8:38am UTC](https://forum.inductiveautomation.com/t/posting-a-query-from-ignition-to-cloud-using-rest-api-with-auth/63141 "2022-08-18T08:38:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdulmalek\_aleshekh](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abdulmalek\_aleshekh](https://forum.inductiveautomation.com/u/abdulmalek_aleshekh)\
**Post date:** [August 18, 2022, 8:38am UTC](https://forum.inductiveautomation.com/t/posting-a-query-from-ignition-to-cloud-using-rest-api-with-auth/63141/1 "2022-08-18T08:38:57Z")

</div>

Hello,

I am trying to post a query to cloud using through REST API every 5 seconds. I am able to post and get the data using postman and I want to do it using Ignition. I evaluated that the best way to do that is by using “timer” in “Gateway events”, and I don’t know how to do it. If someone cloud help with the program or refer to a better way to perform this, that would be great.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 18, 2022, 12:33pm UTC](https://forum.inductiveautomation.com/t/posting-a-query-from-ignition-to-cloud-using-rest-api-with-auth/63141/2 "2022-08-18T12:33:46Z")

</div>

Post your current code (obscure any keys) and we can help you convert to jython. What version of Ignition are you using? (It would be best to build around Ignition’s `system.net.httpClient` scripting object.)

{When you paste your code into the forum, be sure to re-select it and click the \</\> button. That will enclose it in a code block to preserve formatting.}

---

<div class="post-metadata">

**Author:** ![abdulmalek\_aleshekh](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abdulmalek\_aleshekh](https://forum.inductiveautomation.com/u/abdulmalek_aleshekh)\
**Post date:** [August 21, 2022, 7:27am UTC](https://forum.inductiveautomation.com/t/posting-a-query-from-ignition-to-cloud-using-rest-api-with-auth/63141/3 "2022-08-21T07:27:12Z")

</div>

Hello, this is the format I have which runs in the script console and I can read the query using postman. I would like to apply the same query in a timer that runs every 5 seconds. This is the code:

```auto
client = system.net.httpClient() 
url = 'my_url' 
token = 'my_token' 
headers = {'authorization':token} 
ID = {
  "valueSource": "Memory",
  "VariableName": "name",
  "VariableValue": 123,
  "tagType": "AtomicTag"
}
response = client.post(url, headers, ID)

```

Also, Can I send the query using the tag id and not specifically naming each tag detail (incase my tag value changes)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 21, 2022, 1:40pm UTC](https://forum.inductiveautomation.com/t/posting-a-query-from-ignition-to-cloud-using-rest-api-with-auth/63141/4 "2022-08-21T13:40:43Z")

</div>

> [@abdulmalek\_aleshekh](#):
>
> same query in a timer

So, place that code in project library script. The values that are constant or long-lived would remain un-indented, `client` and probably `token` and `uri`. The rest would be indented within a function `def`, where the changeable parts are function arguments. Call the function from a gateway timer script. { But consider using a tag change event to omit unnecessary calls, since the source appears to be tag values. }

> [@abdulmalek\_aleshekh](#):
>
> tag id and not specifically naming each tag

Sure, you just construct your `ID` payload with variables instead of constants. The variables could be arguments to the function.
