Search Documentation
Search for a documentation page...
Scripts API
Run one JavaScript program on the server that calls many Store API operations in a single request, with the caller's own credential.
A script is a JavaScript program that calls Store API operations on the server. Use one when a job needs many calls: sweeping every page of a list, cross-referencing resources (every order that contains a product), updating a filtered set in bulk, or boiling large responses down to a few fields. For one lookup or one write, call the operation itself.
Run a script
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | JavaScript source, up to 64 KB. Top-level await and return work |
readOnly | boolean | No | Refuse every operation that is not a GET. Defaults to false |
Inside the program every operation is await tools.<operationId>(input). Path and query parameters are top-level fields of input. The JSON request body goes under body:
Each call resolves to { status, statusText, body }, non-2xx answers included, so check status before you trust body. Operation names are the operationIds in the OpenAPI spec.
This program reads every product in a collection and returns only the fields it needs:
Response (200)
result is the program's return value, or null.
Credentials and permissions
Every call in the program acts as the caller. It uses the same credential, so it reaches the same store, an API key keeps its scopes, and an OAuth connection keeps the team member's permissions. A call the caller could not make directly answers 403 inside the program.
Any store API key may run scripts, except a key limited to the storefront preset or the feedback scope. Any team member connected over OAuth may run them.
Limits
| Limit | Value |
|---|---|
| Runtime | 60 seconds |
| API calls | 100 per run |
| Time per call | 30 seconds |
| Concurrent calls | 8 at a time with Promise.all |
| Source | 64 KB |
| Result | 128 KB |
The program runs in an isolated sandbox with plain JavaScript only. There is no fetch, no filesystem and no import. A script cannot call runStoreScript itself.
Operations a script can't call
Operations that need the merchant's approval are refused inside a script. The 400 names the operation, so you can call it directly after asking:
- refunds, gift cards, wholesale orders and completing a draft order,
- anything sent to customers,
- team access and ownership,
- every delete, remove and connect operation,
- imports, unless they are a
dryRun, - catalog reset, live payments, and changes to the store's currency, address or published state.
Writes are not rolled back
When a program fails partway, the calls it made before the failure have happened. Read the affected records before you run it again.
Errors
| Status | Description |
|---|---|
400 | Invalid body, or the program failed: a syntax or runtime error, a limit, or a refused operation. error has the message |
Related
- MCP Server – agents on the full server can run scripts; the directory versions leave them out