Invokes a function
Invoke a Supabase Edge Function.
Blob, ArrayBuffer, File, FormData and String. If it doesn't match any of these types we assume the payload is json, serialize it and attach the Content-Type header as application/json. You can override this behavior by passing in a Content-Type header of your own.json, blob and form-data depending on the Content-Type header sent by your function. Responses are parsed as text by default.The name of the Function to invoke.
Options for invoking the Function.
const { data, error } = await supabase.functions.invoke('hello', {
  body: { foo: 'bar' }
})
import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  body: { foo: 'bar' }
})
if (error instanceof FunctionsHttpError) {
  const errorMessage = await error.context.json()
  console.log('Function returned an error', errorMessage)
} else if (error instanceof FunctionsRelayError) {
  console.log('Relay error:', error.message)
} else if (error instanceof FunctionsFetchError) {
  console.log('Fetch error:', error.message)
}
const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  body: { foo: 'bar' }
})
const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  body: { foo: 'bar' },
  method: 'DELETE'
})
import { createClient, FunctionRegion } from '@supabase/supabase-js'
const { data, error } = await supabase.functions.invoke('hello', {
  body: { foo: 'bar' },
  region: FunctionRegion.UsEast1
})
const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  method: 'GET'
})