> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ollie.shop/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploying a function

> Create the function record, configure its trigger, deploy the code from the CLI or the Admin, activate it, and keep it healthy

A function is two things: a **record** in a store version (name, trigger, type, priority, error behaviour, active flag) and the **code** deployed to it. Both are needed before it runs.

## 1. Create the record

**Admin**

**Functions → Create Function**: name, **Active** (leave it off until the code is deployed), **On error** (Skip or Throw), **Priority**, and the **Version**. You can drop the code zip here too; most people deploy from the CLI instead.

![Create Function form](https://mintcdn.com/ollie/ZKpSeyUd64Smy50J/images/admin-function-new.png?fit=max\&auto=format\&n=ZKpSeyUd64Smy50J\&q=85\&s=ea2eaa339a456a84c7a3b8c78318901b)

Then open the function and fill in **Trigger Configuration**: provider, URL, HTTP method, trigger type (Request or Response), optional conditions. Click **Save**. See [Triggers](/ollie-shop/functions/triggers.md).

**CLI**

```bash theme={"system"}
npx ollieshop function create \
  --version-id <version-uuid> \
  --name "Block PO boxes" \
  --invocation request \
  --trigger-url "https://acme.vtexcommercestable.com.br/api/checkout/pub/orderForm/:id/attachments/shippingData" \
  --trigger-expression 'method in ["POST"]' \
  --on-error throw \
  --priority 0
```

Returns the function id. `--active` is off by default. See [Record commands](/ollie-shop/cli/resources.md#function).

Note the defaults differ: the Admin form starts with **Skip** and **Active**, the CLI with **Throw** and inactive.

## 2. Write and test the code

Put the code in `functions/<name>/index.ts` with a named `handler` export ([Writing a function](/ollie-shop/functions/writing-a-function.md)), add a `function.json` mirroring the trigger, and run it locally:

```bash theme={"system"}
npx ollieshop function dev
```

See [function dev](/ollie-shop/cli/function-dev.md) for the local pipeline and the `curl` calls to drive it.

## 3. Deploy the code

**CLI**

```bash theme={"system"}
npx ollieshop deploy --function-id <function-uuid> --name block-po-boxes --wait
```

The CLI zips the project, uploads it, and follows the build. `--name` is the folder name under `functions/`. See [deploy](/ollie-shop/cli/deploy.md) for what goes into the zip and `.ollieignore`.

**Admin**

Open the function, **Code Management**, and drop a zip (up to 10 MB) with `package.json` and `index.ts` at its root. The build status and log appear below the upload box.

The build installs your `package.json` dependencies, bundles everything into one file, and creates or updates the function's runtime. The first deploy takes longer than the following ones.

## 4. Activate

Turn **Active** on in the function's General Configuration (or `ollieshop function update --function-id <id> --active true`). The hub refreshes its list of active functions within **3 minutes**; new code is used as soon as the build succeeds.

## Checking it runs

* The **Builds** tab lists every build with its status and log.
* In the checkout, trigger the call the function watches and look for its effect. For a response function that adds `extensions`, read them with `useCheckoutSession()` in a component or in the browser's network tab of the checkout's own server action.
* A function with **Throw** that fails makes the call return "An unexpected error occurred". Switch it to **Skip** while debugging.

## Updating and retiring

* Redeploy with the same `deploy` command. Each build replaces the previous code.
* The runtime settings (Node version, memory, time limit, runtime library) are set on the **first** deploy and not changed by later ones. When a function needs a capability shipped after it was first created, create a new function record and deploy there.
* To stop a function, turn **Active** off. To remove it, **Delete Function** in the Danger Zone; this cannot be undone.

## Related

* [Managing Versions](/ollie-shop/configuration/versions.md): functions belong to a version and are copied when it is duplicated
* [Environment Variables](/ollie-shop/configuration/env-vars.md): secrets your function reads with `process.env`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.