# Update function draft

> Update an existing function. sourceCode / dependencies edit the draft without triggering a build — they go live on the next POST /v1/functions/{functionId}/deploy. httpEnabled is applied to the deployed function immediately, so turning the public endpoint on or off does not require a redeploy.

`PATCH https://api.zavu.dev/v1/functions/{functionId}`

Update an existing function. `sourceCode` / `dependencies` edit the draft without triggering a build — they go live on the next `POST /v1/functions/{functionId}/deploy`. `httpEnabled` is applied to the deployed function immediately, so turning the public endpoint on or off does not require a redeploy.

## Parameters

- `functionId` (path, string, required): Zavu Function ID.

## Body

- `files` (object): The project's source files, keyed by path relative to the project root (e.g. `index.ts`, `lib/orders.ts`). Imports between them are resolved when the function is built, so a function can be split across as many files as it needs. Paths must be relative and use forward slashes; `..`, `node_modules/` and `package.json` are rejected. npm packages are not uploaded here — declare them under `dependencies` and Zavu installs them. Limits: 200 files and 900,000 bytes for the whole tree.
  - `{key}` (string)
- `entrypoint` (string): Which file in `files` is the entry point. Defaults to `index.ts`.
- `sourceCode` (string): Shortcut for a single-file function: exactly equivalent to sending `files` with one entry named after `entrypoint` (`index.ts` by default). Fully supported — use whichever fits. If both are sent, `files` wins.
- `dependencies` (object): New dependency map (replaces existing dependencies).
  - `{key}` (string)
- `httpEnabled` (boolean): Expose the function on its public HTTPS URL, or take it down. Applies to the already-deployed function without redeploying; the URL is returned as `publicUrl`.

## Responses

### 200

Draft updated.

- `function` (object, required): A Zavu Function — user-supplied TypeScript that runs in Zavu Cloud and reacts to messaging events or HTTP requests.
  - `id` (string, required)
  - `slug` (string, required): URL-safe identifier, unique per project.
  - `name` (string, required)
  - `description` (string, nullable)
  - `runtime` (string, required): Runtime the function is deployed on. One of: `nodejs24`.
  - `status` (string, required): Lifecycle status of a Zavu Function. One of: `draft`, `bundling`, `deploying`, `active`, `failed`, `disabled`.
  - `timeoutSec` (integer, required): Per-invocation timeout in seconds.
  - `memoryMb` (integer, required): Memory allocation in MB.
  - `httpEnabled` (boolean, required): Whether the function can be invoked over HTTPS via its public URL.
  - `publicUrl` (string<uri>, nullable): HTTPS endpoint, present only while httpEnabled is true. Null otherwise, including for a function that was previously exposed — the stored URL stops serving the moment HTTP is turned off, so it is never returned.
  - `dependencies` (object, required): npm dependencies installed in the function bundle. Keys are package names, values are semver ranges.
    - `{key}` (string)
  - `activeDeploymentId` (string, nullable): ID of the deployment currently serving traffic.
  - `createdAt` (string<date-time>, required)
  - `updatedAt` (string<date-time>, required)

### 400

No fields provided.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Function not found.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X PATCH "https://api.zavu.dev/v1/functions/function_abc123" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "files": {
    "index.ts": "import { formatOrder } from '\''./lib/orders'\'';\n\nexport default async function handler(event) {\n  return { statusCode: 200, body: formatOrder(event) };\n}\n",
    "lib/orders.ts": "export function formatOrder(event) {\n  return JSON.stringify(event);\n}\n"
  }
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.functions.update("function_abc123", {
  files: {
    "index.ts": "import { formatOrder } from './lib/orders';\n\nexport default async function handler(event) {\n  return { statusCode: 200, body: formatOrder(event) };\n}\n",
    "lib/orders.ts": "export function formatOrder(event) {\n  return JSON.stringify(event);\n}\n",
  },
});

console.log(result);
```
