# Tag Change Triggering Gateway Event Script

**URL:** <https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 17, 2024, 5:42pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944 "2024-12-17T17:42:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Purcella](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Nathan\_Purcella](https://forum.inductiveautomation.com/u/Nathan_Purcella)\
**Post date:** [December 17, 2024, 5:42pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/1 "2024-12-17T17:42:19Z")

</div>

Good afternoon! I am just starting to get my feet wet with Ignition and need some help getting a tag change to trigger a post call to an API.  
I am trying to use a tag change from an OPC server to drive a httpPost for a telemetry device. I have been able to get the gateway event to successfully trigger on a local installation of ignition using a demo OPC server but have not been able to replicate the same results with the Dev Server that my company has. I can see the values changing on the OPC side and have even tried to just attach the change action to the timestamp to try to get the event to trigger.  
Here is an image of my gateway configuration script on the Dev Server.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/654bd03159b386d929fd32cc0965b709c90ae85a.png)

The Script works both through the script console and through Postman, so I don't believe the issue is my script.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 17, 2024, 5:54pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/2 "2024-12-17T17:54:18Z")

</div>

> [@Nathan\_Purcella](#):
>
> The Script works both through the script console and through Postman,

These calls originate from _your_ PC, while the tag change event script is executing on whatever server the Ignition Gateway is running on. Does that server have access to the IP you're calling?

You should log or print the response so you know what's happening.

> **[system.util.getLogger | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-getLogger)**
>
> Returns a Logger object that can be used to log messages to the console.

---

<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:** [December 17, 2024, 6:36pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/3 "2024-12-17T18:36:44Z")

</div>

Also, do **not** create `system.net.httpClient()` instances for every event, as that leads to memory leaks.

Write your script as a function in a project library, and assign to `client` **outside** the function. (That makes it persistent for multiple calls.)

---

<div class="post-metadata">

**Author:** ![Nathan\_Purcella](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Nathan\_Purcella](https://forum.inductiveautomation.com/u/Nathan_Purcella)\
**Post date:** [December 17, 2024, 6:44pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/4 "2024-12-17T18:44:34Z")

</div>

I was able to get logging enabled and it looks like I am getting a response, but the logs don't go into more detail what the response is. I also added a get function to try to elicit a more detailed response. Is there a way to get a better response from the postlogs?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/b/fbd3a57f5c35cac4274f1147252a5796fe7668e4.png)

I will add the client to outside the function.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 17, 2024, 6:51pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/5 "2024-12-17T18:51:17Z")

</div>

Show us your logging code

---

<div class="post-metadata">

**Author:** ![Nathan\_Purcella](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Nathan\_Purcella](https://forum.inductiveautomation.com/u/Nathan_Purcella)\
**Post date:** [December 17, 2024, 7:33pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/6 "2024-12-17T19:33:32Z")

</div>

```python
client = system.net.httpClient()
response = client.post ('http://10.201.150.11/api/v0/inputs/1')
print(response)
logger = system.util.getLogger("postlogs")
logger.debug("response")
logger.info("response")

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 17, 2024, 7:34pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/7 "2024-12-17T19:34:13Z")

</div>

> [@Nathan\_Purcella](#):
>
> ```python
> logger.debug("response")
> logger.info("response")
> 
> ```

You're just logging the literal string "response".

---

<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:** [December 17, 2024, 7:49pm UTC](https://forum.inductiveautomation.com/t/tag-change-triggering-gateway-event-script/99944/8 "2024-12-17T19:49:02Z")

</div>

> [@Nathan\_Purcella](#):
>
> ```python
> client = system.net.httpClient()
> response = client.post ('http://10.201.150.11/api/v0/inputs/1')
> 
> ```

You haven't put your code in a script library function. 🤷‍♂️

> [@Nathan\_Purcella](#):
>
> ```python
> logger = system.util.getLogger("postlogs")
> logger.debug("response")
> 
> ```

The assignment to `logger` should also be outside the function, to make it persistent.
