Skip to content

NetlifyExtensionClient

The NetlifyExtensionClient provides different methods to interact with both the Netlify API and the Extension API.

Review TypeScript definitions in the SDK

When you install the Netlify SDK, you have access to the TypeScript definitions directly in the @netlify/sdk package. You can browse through the definition files individually or review the type definition inline depending on your code editor.

Usage example

src/functions/my-function.ts
import { withNetlifySDKContext } from "@netlify/sdk/ui/functions";
export default withNetlifySDKContext((req, context) => {
const { accountId, auth, client } = context;
const accountInfo = await client.getAccount(accountId);
// Using the user’s OAuth connection to make a request to a third-party API
await fetch("https://api.example.com/project", {
headers: {
Authorization: `Bearer ${auth.providerToken}`,
},
method: "POST",
body: JSON.stringify({
name: `project_${accountInfo.name}`,
}),
});
return Response.json({});
});

Methods

createConnectConfiguration

createConnectConfiguration({ teamId, dataLayerId, config, name, prefix? })

Creates a Connect configuration for an extension installation.

Parameters

NameType
teamIdstring
dataLayerIdstring
configConnectorConfiguration
namestring
prefixstring optional

Returns

An empty Promise.

createEnvironmentVariable

createEnvironmentVariable({ accountId, siteId, key, values })

Creates a new environment variable for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
isSecretboolean optional Defaults to false.
keystring
scopesEnvironmentVariableScopeType[] optional
siteIdstring optional
valuesEnvironmentVariableValue[]

Returns

A Promise with an EnvironmentVariableValue object.


createOrUpdateVariable

createOrUpdateVariable({ accountId, siteId, key, value })

Creates or updates a single environment variable for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
isSecretboolean optional. Defaults to false.
keystring
scopesEnvironmentVariableScopeType[] optional
siteIdstring optional
valueEnvVarRequest

Returns

A Promise with an EnvironmentVariable object.


createOrUpdateVariables

createOrUpdateVariables({ accountId, siteId, variables })

Creates or updates all environment variables in the variables object for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
isSecretboolean optional. Defaults to false.
scopesEnvironmentVariableScopeType[] optional
siteIdstring optional
variablesRecord<string, EnvVarRequest>

Returns

A Promise with an array of EnvironmentVariable.


createSiteConfiguration

createSiteConfiguration(teamId, siteId, config)

Creates a site configuration for an extension installation.

Parameters

NameType
teamIdstring
siteIdstring
configSiteConfiguration

Returns

An empty Promise.


createTeamConfiguration

createTeamConfiguration(teamId, config)

Creates a team configuration for an extension installation.

Parameters

NameType
teamIdstring
configTeamConfiguration

Returns

An empty Promise.


createVisualEditorConfiguration

createVisualEditorConfiguration({ teamId, siteId, config, name, projectId, prefix })

Creates a visual editor configuration for an extension installation.

Parameters

NameType
teamIdstring
siteIdstring
dataLayerIdstring
configConnectorConfiguration
namestring
projectIdstring
prefixstring

Returns

An empty Promise.


deleteConnectConfiguration

deleteConnectConfiguration({ teamId, dataLayerId, configurationId })

Deletes a Connect configuration for uninstalling the extension.

Parameters

NameType
teamIdstring
dataLayerIdstring
configurationIdstring

Returns

An empty Promise.


deleteEnvironmentVariable

deleteEnvironmentVariable({ accountId, siteId, key })

Deletes an environment variable for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
siteIdstring optional
keystring

Returns

An empty Promise.


deleteEnvironmentVariables

deleteEnvironmentVariables({ accountId, siteId, variables })

Deletes all environment variables specified in the variables array for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
siteIdstring optional
variablesstring[]

Returns

An empty Promise.


deleteSiteConfiguration

deleteSiteConfiguration(teamId, siteId)

Deletes a site configuration for uninstalling the extension.

Parameters

NameType
teamIdstring
siteIdstring

Returns

An empty Promise.


deleteTeamConfiguration

deleteTeamConfiguration(teamId)

Deletes a team configuration for uninstalling the extension.

Parameters

NameType
teamIdstring

Returns

An empty Promise.


deleteVisualEditorConfiguration

deleteVisualEditorConfiguration({ teamId, siteId, configurationId, projectId })

Deletes a visual editor configuration for uninstalling the extension.

Parameters

NameType
teamIdstring
siteIdstring
configurationIdstring
projectIdstring

Returns

An empty Promise.


getAccount

getAccount(accountId)

Gets an account by ID and returns account information.

Parameters

NameType
accountIdstring

Returns

A Promise with an Account object.


getConnectConfiguration

getConnectConfiguration(teamId, dataLayerId, configurationId)

Gets a Connect configuration by the specified team ID, data layer ID, and configuration ID.

Parameters

NameType
teamIdstring
dataLayerIdstring
configurationIdstring

Returns

A Promise with an ConnectorConfiguration object.


getEnvironmentVariables

getEnvironmentVariables({ accountId, siteId })

Gets all environment variables for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
siteIdstring optional

Returns

A Promise with an array of EnvironmentVariable.


getSite

getSite(siteId)

Gets a site by ID and returns site information.

Parameters

NameType
siteIdstring

Returns

A Promise with a Site.


getSiteConfiguration

getSiteConfiguration(teamId, siteId)

Returns the extension configuration for a site for the current extension.

Parameters

NameType
siteIdstring
teamIdstring

Returns

A Promise with an ExtensionResponse) object.


getSites

getSites()

Gets all sites for an account.

Returns

A Promise with an array of Site.


getTeamConfiguration

getTeamConfiguration(teamId)

Returns the extension configuration for a team for the current extension.

Parameters

NameType
teamIdstring

Returns

Returns a Promise with an ExtensionResponse object.


getVisualEditorConfiguration

getVisualEditorConfiguration(teamId, siteId, configurationId)

Gets a visual editor configuration by the specified team ID, data layer ID, and configuration ID.

Parameters

NameType
teamIdstring
siteIdstring
configurationIdstring

Returns

A Promise with an ConnectorConfiguration object.


installExtensionOnTeam

installExtensionOnTeam(teamId, hasDataIntegration)

Installs this extension for a team.

Parameters

NameType
hasDataIntegrationboolean
teamIdstring

Returns

An empty Promise.


patchEnvironmentVariable

patchEnvironmentVariable({ accountId, siteId, key, context, value, contextParameter })

Creates or updates an environment variable for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
siteIdstring optional
keystring
contextstring
valuestring
contextParameterstring optional

Returns

A Promise with an EnvironmentVariable object.


removeBuildToken

removeBuildToken(accountId, siteId)

Removes the build token for a site.

Parameters

NameType
accountIdstring
siteIdstring

Returns

An empty Promise.


setBuildToken

setBuildToken(accountId, siteId, token)

Sets the build token for a site. Build tokens can be created using the generateBuildToken method.

Parameters

NameType
accountIdstring
siteIdstring
tokenstring

Returns

A Promise with an EnvironmentVariable object.


uninstallExtensionOnTeam

uninstallExtensionOnTeam(teamId)

Uninstalls this extension for a team, which also deletes the configuration.

Parameters

NameType
teamIdstring

Returns

An empty Promise.


updateConnectConfiguration

updateConnectConfiguration({teamId, dataLayerId, configurationId, name, prefix?, config})

Updates a Connect configuration, based on the specified configuration ID.

Parameters

NameType
teamIdstring
dataLayerIdstring
configurationIdstring
namestring
prefixstring optional
configConnectorConfiguration

Returns

An empty Promise.


updateEnvironmentVariable

updateEnvironmentVariable({ accountId, siteId, key, values })

Updates an existing environment variable for a site when passed a siteId. When not passed a siteId, operates on the team level.

Parameters

NameType
accountIdstring
siteIdstring optional
keystring
valuesEnvironmentVariableValue[]

Returns

A Promise with an EnvironmentVariable object.


updateSite

updateSite(siteId, changes?)

Updates a site with the given changes.

Parameters

NameType
siteIdstring
changesPartial<Site>

Returns

A Promise with a Site object.


updateSiteConfiguration

updateSiteConfiguration(teamId, siteId, config)

Updates the extension configuration for a site.

Parameters

NameType
teamIdstring
siteIdstring
configSiteConfiguration

Returns

An empty Promise.


updateTeamConfiguration

updateTeamConfiguration(teamId, config)

Updates the extension configuration for a team.

Parameters

NameType
teamIdstring
configTeamConfiguration

Returns

An empty Promise.


updateVisualEditorConfiguration

updateVisualEditorConfiguration({teamId, siteId, configurationId, config, name, projectId, prefix })

Updates a visual editor configuration, based on the specified configuration ID.

Parameters

NameType
teamIdstring
siteIdstring
configurationIdstring
configConnectorConfiguration
namestring
projectIdstring
prefixstring

Returns

An empty Promise.


Got it!

Your feedback helps us improve our docs.