# Gateway Scheduled Script - API Error

**URL:** <https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648>\
**Category:** Ignition\
**Created:** [February 20, 2025, 7:03pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648 "2025-02-20T19:03:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad\_Medley](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Brad\_Medley](https://forum.inductiveautomation.com/u/Brad_Medley)\
**Post date:** [February 20, 2025, 7:03pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/1 "2025-02-20T19:03:56Z")

</div>

# Goal:

To read with an API and then write updates to a different API through a schedule on the gateway.

# Problem:

Script will run in the script console but does not complete past the API in the Scheduled Gateway Event.

# Script Console:

## Code Block:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/0640be062c1356175c7620ed0eac2e0c3b7055c9.png)

## Results:

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

# Gateway Event - Scheduled

## Script

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

## Results:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/d/9d973ca0719e3f006871be9887de6bf31fba88cd.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 20, 2025, 7:06pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/2 "2025-02-20T19:06:12Z")

</div>

Please post code - not pictures of code (unless the context is important, in which case post both) so we can copy them for testing or modification. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<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:** [February 20, 2025, 7:31pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/3 "2025-02-20T19:31:27Z")

</div>

Don't `logger.error("some error" + str(e)` - you lose the except trackback and cause information, the most valuable part.

Use `logger.error("Some error", e)`, so that the exception goes through the automatic logging machinery and captures the stacktrace.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [February 20, 2025, 8:02pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/4 "2025-02-20T20:02:15Z")

</div>

Additionally, stuff this script into a [Project Library Script](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/project-library) and put the initialization of the `httpClient` outside of any function definitions so you can reuse the same client instead of spawning a new one every time the function runs.

Something along the lines of:

```python
import json
logger = system.util.getLogger("SmartSheetUpdate")

SHEET_HEADERS = {}
SHEET_URL = "https://some url here"

sheetClient = system.net.httpClient()

def abc(payload):
	""" """
	
	response = sheetClient.get(url=SHEET_URL, headers=SHEET_HEADERS)

```

---

<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:** [February 20, 2025, 8:43pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/5 "2025-02-20T20:43:25Z")

</div>

Once in a project library, you may want to install my Integration Toolkit and do this:

```python
@system.util.runInGateway
def abc(payload):
	...

```

... so you can call it in the designer but it will run in the gateway. And you'll likely be able to see what is wrong.

(Designer scope is a variant of Vision Client scope--not related to Gateway Scope at all.)

---

<div class="post-metadata">

**Author:** ![Brad\_Medley](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Brad\_Medley](https://forum.inductiveautomation.com/u/Brad_Medley)\
**Post date:** [February 21, 2025, 9:54pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/6 "2025-02-21T21:54:56Z")

</div>

Where do I find this integration toolkit?

---

<div class="post-metadata">

**Author:** ![Brad\_Medley](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Brad\_Medley](https://forum.inductiveautomation.com/u/Brad_Medley)\
**Post date:** [February 21, 2025, 9:55pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/7 "2025-02-21T21:55:29Z")

</div>

I did this definitely much easier

---

<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:** [February 21, 2025, 10:10pm UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/8 "2025-02-21T22:10:02Z")

</div>

> [@Brad\_Medley](#):
>
> find this integration toolkit?

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934):
>
> Automation Professionals is pleased to announce the immediately availability of a major upgrade to its free Simulation Aids Integration Toolkit module. The new feature justifying the "major upgrade" language is the implementation of eleven thirty-one new expression functions which use iteration to accomplish complex transforms of datasets and lists, to or from other datasets and lists, applying filtering, ordering, and computed new columns along the way. While there are certain operations that…

And then to my [Module Sales](https://www.automation-pros.com/modulesales.html) page. (But this one is free.)

---

<div class="post-metadata">

**Author:** ![Brad\_Medley](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Brad\_Medley](https://forum.inductiveautomation.com/u/Brad_Medley)\
**Post date:** [March 21, 2025, 12:38am UTC](https://forum.inductiveautomation.com/t/gateway-scheduled-script-api-error/102648/9 "2025-03-21T00:38:39Z")

</div>

My issue is our network firewall.
