Skip to main content
A function is a folder under functions/ in your project with an index.ts that exports a named handler:
functions/block-po-boxes/index.ts
The export must be named handler. A default export is ignored.

What you receive

Both are standard Request / Response objects with one improvement: their bodies can be read more than once. await req.json() in one function and again in the next is fine. Two things to remember:
  • A GET request has no body, so req.json() throws on it. Check req.method first.
  • formData() is not supported; read text() and parse it yourself.
The URL of req is the absolute platform URL, for example https://acme.vtexcommercestable.com.br/api/checkout/pub/orderForm/<id>/items.

What you can return

Anything else (null, an object, a string) is an error: Custom function must return a Request, a Response, or undefined.

Rewriting a request

Enriching a response

The checkout parses the platform’s response into the session. Fields you add under extensions surface as session.extensions in useCheckoutSession, which is how a function hands data to a component:

Rejecting an action with a message

A request function that returns a Response stops the call. To show the shopper a message instead of a generic error, answer with a 4xx status and the x-ollie-shop-custom-message header; the checkout displays that text:
Use a 4xx status for rejections. The checkout may retry 5xx responses, which would run your function again.

Several functions on one call

  • All matching request functions run first, then the platform is called once, then all matching response functions run.
  • Within each kind, functions run in priority order: lowest number first, ties by creation date. Priority never reorders a request function after a response function.
  • Each function receives the output of the previous one: a request rewritten by priority 0 is what priority 1 sees.
  • A request function that returns a Response ends the chain: the remaining request functions, the platform call and the response functions are skipped.

Errors

A function fails when it throws, returns an invalid value, exceeds its time limit, or its trigger expression cannot be evaluated. What happens next is the function’s Error Behavior: Use Throw only for rules that must block the action. For anything else, catch your own errors and use Skip, so a third-party outage cannot break checkout.

Environment variables and secrets

The store’s Environment Variables are available as process.env.MY_KEY inside the handler. They are injected per call, so read them in the handler, not at the top of the module:
Values are used exactly as saved; trim them in the Admin rather than in code. Every function of the store receives the same variables.

Logging

console.log, console.warn and console.error are captured as structured logs with the function id and store id. Function logs are available on request from Ollie support. Keep lines short and avoid logging full payloads.

Runtime and limits

The runtime settings of a function (Node version, memory, time limit and runtime library) are fixed when the function is first deployed. Redeploying code does not update them. If a function was created long ago and misses a capability described here, create a new function and deploy to it.

Types

The platform package that wraps your handler is not published, so declare the context type yourself or copy this one:
functions/types.ts