# Trigger a script from outside

**URL:** <https://forum.inductiveautomation.com/t/trigger-a-script-from-outside/63678>\
**Category:** Ignition\
**Created:** [September 1, 2022, 2:39pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-from-outside/63678 "2022-09-01T14:39:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor\_lefebvre](https://avatars.discourse-cdn.com/v4/letter/v/b5a626/32.png) [@victor\_lefebvre](https://forum.inductiveautomation.com/u/victor_lefebvre)\
**Post date:** [September 1, 2022, 2:39pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-from-outside/63678/1 "2022-09-01T14:39:24Z")

</div>

Hello,

I have a script that I would like to run when something happen from outside of the gateway.  
For example I have a script that import tags from json file and I have an external system that produce those json files, I would like to have the possibility to deploy automatically the changes without any human action.  
So for example is it possible to trigger a script every time there is a new file in a folder on the gateway?  
Or maybe it is possible to send a message to the gateway with an external API and use the message handler of the gateway event script?

Thanks

---

<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:** [September 1, 2022, 2:42pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-from-outside/63678/2 "2022-09-01T14:42:45Z")

</div>

1. Java can monitor a folder for changes, though you need a long-lived thread. That has serious memory leak hazards if not cleaned up at the correct times (project restarts in particular).

2. The WebDev module is specifically designed to expose an API to external callers. You have total control via scripting how Ignition responds. Consider having the external system simply POST the new JSON file to Ignition this way.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [September 1, 2022, 2:44pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-from-outside/63678/3 "2022-09-01T14:44:18Z")

</div>

Depending on your needs you may also be able to get away with a gateway timer script checking the folder periodically.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 1, 2022, 3:08pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-from-outside/63678/4 "2022-09-01T15:08:07Z")

</div>

A few posts that may help,

> [@Gateway Script to monitor directory for new files](https://forum.inductiveautomation.com/t/gateway-script-to-monitor-directory-for-new-files/16124/1):
>
> Hi, I’m looking for some advice as to the best way to monitor a network directory location for new files. We have an external provider that FTP’s files into a specific directory on our network, and I would like the Ignition Gateway to monitor this directory and read in the new file as a string. From that point, I have some XML parsing code written and tested, I just can’t figure out how to monitor and get new files read in. (For completeness - once I have read and parsed the file I will move i…

> [@Managing multiple asynchronous threads](https://forum.inductiveautomation.com/t/managing-multiple-asynchronous-threads/37185):
>
> I've followed this post for monitoring a directory for file changes and I think I have created more than one watch service in different threads. How do I monitor, manage, and delete these threads?

Using a timer is probably the easiest and best, unless you're interested if files change, then the file watcher may be what you want.
