> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting.md).

# Custom scripting

## Introduction

Typically, [transform functions](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/map-shape) are used to change data as it moves through a process flow. However, if your requirements are more complex than standard transform functions can handle, custom scripting is the answer.

With Patchworks custom scripting, you write and maintain scripts centrally — in our proprietary script editor — then use them wherever they're needed throughout the platform. From a single **build & test** workspace you can code by hand or [build with AI](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/creating-a-script-with-ai), [test with realistic inputs](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts), then [version and deploy](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/deploying-scripts-and-managing-versions) your scripts — with full visibility of where each one is used.

<div data-with-frame="true"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FhOfXAUF4pONGxmCdHRds%2FFull%20Screen%20Editor%20with%20test%20window.png?alt=media&amp;token=47948098-ae11-4bd1-b4be-9a58d04a711d" alt=""><figcaption></figcaption></figure></div>

### Script types

Every script is created as one of six types. The type sets the starter template you begin from, and the inputs/outputs the script is written against — so you always start from a shape that matches the job:

| Script type  | Typical use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| General      | Runs as a step in a process flow, transforming the payload passed to it — via the [script shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/script-shape) or the map shape's [script transform function](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/map-shape/working-with-field-transformations/available-transform-functions/other-transform-functions/script-transform-function). |
| Pre-auth     | Prepares an authentication request before it's sent — used with [connector builder authentication methods](https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/3-authentication-methods/authentication-method-options/pre-request-script).                                                                                                                                                                                                                                                     |
| Post-auth    | Processes an authentication response — for example, extracting and shaping tokens for subsequent requests.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Pre-request  | Adjusts a connector [endpoint request](https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/endpoint-options/pre-request-script) before it's sent.                                                                                                                                                                                                                                                                                                                                  |
| Post-request | Processes a connector endpoint response before it's passed on.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| Pagination   | Implements [custom pagination logic](https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/endpoint-options/pagination/script-pagination) for connector endpoints.                                                                                                                                                                                                                                                                                                                   |

{% hint style="info" %}
The script type is a guide, not a restriction. It determines the starter template and the inputs shown when you're building and testing, but it doesn't limit where the script can be attached.&#x20;
{% endhint %}

### Supported languages

You can create scripts in any of seven coding languages: **C#**, **Go**, **JavaScript**, **PHP**, **Python**, **Ruby** and **Rust**.

When you create a script, you choose the language and a runtime version (for example, `Node 24` for JavaScript) — the versions currently available for each language are shown in the `runtime version` dropdown. The runtime version can be changed at any time, but the language is locked as soon as you save your first version of the script — so choose carefully!

### Supported libraries & packages

All of our coding languages are supported with default packages. In addition, the following libraries/versions are included:

| Language   | Additional libraries                                           |
| ---------- | -------------------------------------------------------------- |
| JavaScript | jsrsasign (^10.8.6), xml-js (^1.6.11)                          |
| Python     | requests (2.32.3)                                              |
| PHP        | phpseclib (\~3.0), bcmath, SSH-2.0, PDO\_MYSQL, phpSpreadsheet |
| C#         | System.Xml.ReaderWriter, Newtonsoft.Json                       |

If you want to use a library that isn't included by default, you can embed it directly in your script, or contact Patchworks support to request it.

### AI assistance

You don't have to write scripts yourself! The script editor includes an integrated AI **script assistant** — switch the editor into **AI** mode, describe what you need, and a draft script is generated for you. The assistant knows about expected inputs and value types (payload, metadata, variables and flow variables), so generated scripts are in a form that's ready to use. See [Creating a script with AI](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/creating-a-script-with-ai).

Scripts can also be created conversationally via the [implementation agent](https://doc.wearepatchworks.com/product-documentation/ai/patchworks-ai-studio/platform-agents/implementation-agent) — useful when a script is just one part of a wider build.

### Versions & deployment

Scripts are versioned — each script can hold up to **10 versions**, and saving is separate from deploying:

* **Save** work-in-progress versions as often as you like, without affecting anything that's live.
* **Deploy** a version when you're ready to release it — and update every process flow that uses the script in one action.

See [Deploying scripts & managing versions](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/deploying-scripts-and-managing-versions) for more information. All changes and deployments are recorded, so you have a full audit trail of who changed what, and when.

### Learn more

To get started with custom scripts, see the pages below:

* [Accessing scripts](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/accessing-custom-scripts)
* [Creating & testing custom scripts](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts)
* [Deploying scripts & managing versions](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/deploying-scripts-and-managing-versions)
* [Custom script examples](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/custom-script-examples-general)
