JavaScript: invoke
Invokes a function
Parameters
functionName
(Required)The name of the Function to invoke.
options
(Required)Options for invoking the Function.
Examples
Example 1
const { data, error } = await functions.invoke('hello-world', {
body: { name: 'Ada' },
})
Basic invocation
const { data, error } = await supabase.functions.invoke('hello', {
body: { foo: 'bar' }
})
Error handling
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.error('Function returned an error', errorMessage)
} else if (error instanceof FunctionsRelayError) {
console.error('Relay error:', error)
} else if (error instanceof FunctionsFetchError) {
console.error('Fetch error:', error)
}
Passing custom headers
const { data, error } = await supabase.functions.invoke('hello', {
headers: {
"my-custom-header": 'my-custom-header-value'
},
body: { foo: 'bar' }
})
Calling with DELETE HTTP verb
const { data, error } = await supabase.functions.invoke('hello', {
headers: {
"my-custom-header": 'my-custom-header-value'
},
body: { foo: 'bar' },
method: 'DELETE'
})
Invoking a Function in the UsEast1 region
import { createClient, FunctionRegion } from '@supabase/supabase-js'
const { data, error } = await supabase.functions.invoke('hello', {
body: { foo: 'bar' },
region: FunctionRegion.UsEast1
})
Calling with GET HTTP verb
const { data, error } = await supabase.functions.invoke('hello', {
headers: {
"my-custom-header": 'my-custom-header-value'
},
method: 'GET'
})
Standalone client invoke
const { data, error } = await functions.invoke('hello-world', {
body: { name: 'Ada' },
})
