Functions

invoke

fn (request: InvokeFunctionRequest): Any
fn (request: InvokeFunctionRequest, opts: Map): Any

Invoke a Supabase Edge Function by name. The function receives the JSON body and any additional headers. Set region to run in a specific region (e.g. "us-east-1").

Example

::functions ::supabase::functions

// Simple invocation
result ::functions/invoke(::functions/InvokeFunctionRequest({
  name: "hello-world"
}))

// With body and headers
result ::functions/invoke(::functions/InvokeFunctionRequest({
  name: "process-order",
  body: {order_id: "abc-123", action: "confirm"},
  headers: {"x-custom-header": "value"}
}))

invoke-as

fn (request: InvokeFunctionRequest, access-token: Str): Any
fn (request: InvokeFunctionRequest, access-token: Str, opts: Map): Any

Like invoke, but as a signed-in user. access-token is the Bearer token, so row level security applies as that user.

Example

::functions ::supabase::functions

token ::hot::ctx/get("supabase.user.token")
::functions/invoke-as(::functions/InvokeFunctionRequest({name: "hello-world"}), token)

invoke-http-response

fn (request: InvokeFunctionRequest): ::supabase::api/HttpResponse
fn (request: InvokeFunctionRequest, opts: Map): ::supabase::api/HttpResponse

Invoke an Edge Function and return the full HttpResponse. Authenticates with the service role key when service is true, else access-token when set, else the anon key. A non-2xx status is not an Err: check status.

Example

::functions ::supabase::functions

response ::functions/invoke-http-response(::functions/InvokeFunctionRequest({
  name: "process-order",
  body: {order_id: "abc-123"}
}))
response.status
response.body

invoke-response

fn (request: InvokeFunctionRequest): InvokeResponse
fn (request: InvokeFunctionRequest, opts: Map): InvokeResponse

Like invoke, but returns an InvokeResponse with status, headers and body. A non-2xx status is an Err carrying an HttpError.

Example

::functions ::supabase::functions

response ::functions/invoke-response(::functions/InvokeFunctionRequest({
  name: "process-order",
  body: {order_id: "abc-123"},
  region: "us-east-1"
}))
response.headers
response.body

invoke-service

fn (request: InvokeFunctionRequest): Any
fn (request: InvokeFunctionRequest, opts: Map): Any

Like invoke, with the service role key. Server-side only.

Example

::functions ::supabase::functions

::functions/invoke-service(::functions/InvokeFunctionRequest({name: "nightly-cleanup"}))

Types

InvokeFunctionRequest

InvokeFunctionRequest type {
    name: Str,
    body: Any?,
    headers: Map?,
    region: Str?,
    access-token: Str?,
    service: Bool?
}

InvokeResponse

InvokeResponse type {
    status: Int,
    headers: Map,
    body: Any
}