Skip to content

NetlifyIntegrationClient

The NetlifyIntegrationClient provides different methods to interact with both the Netlify API and the Integration API.

Usage example

src/index.ts
import { NetlifyIntegration } from "@netlify/sdk";
const integration = new NetlifyIntegration();
integration.addApiHandler("cool-function", async (event, context) => {
const { client, accountId, providerOAuthToken } = 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 ${providerOAuthToken}`,
},
method: "POST",
body: JSON.stringify({
name: `project_${accountInfo.name}`,
}),
});
return {
statusCode: 200,
};
});

Methods

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
siteIdstring optional
keystring
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
siteIdstring optional
keystring
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
siteIdstring optional
variablesRecord<string, EnvVarRequest>

Returns

A Promise with an array of EnvironmentVariable.


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.


disableSiteIntegration

disableSiteIntegration(siteId)

Disables this integration for a site, which also deletes the configuration.

Parameters

NameType
siteIdstring

Returns

An empty Promise.


disableTeamIntegration

disableTeamIntegration(teamId)

Disables this integration for a team, which also deletes the configuration.

Parameters

NameType
teamIdstring

Returns

An empty Promise.


enableSiteIntegration

enableSiteIntegration(siteId, config)

Enables this integration for a site, passing a configuration object.

Parameters

NameType
siteIdstring
configobject

Returns

A Promise with a { token: string } object.


enableTeamIntegration

enableTeamIntegration(teamId, config?)

Enables this integration for a team. It is also possible to immediately pass a configuration object with the integration’s configuration.

Parameters

NameType
teamIdstring
configobject

Returns

A Promise with a { token: string } object.


exchangeBuildToken

exchangeBuildToken(siteId)

Validates a build token. Returns the siteId and teamId if the token is valid and returns an error if the token is invalid.

Parameters

NameType
siteIdstring

Returns

A Promise with a BuildTokenValidationResponse object.


generateBuildToken

generateBuildToken(siteId, teamId?)

Generates a build token for a site, allowing a build event handler to use the Build Context API.

Parameters

NameType
siteIdstring
teamId?string

Returns

A Promise with a { token: string } object.


getAccount

getAccount(accountId)

Gets an account by ID and returns account information.

Parameters

NameType
accountIdstring

Returns

A Promise with an Account 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.


getSiteIntegration

getSiteIntegration(siteId)

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

Parameters

NameType
siteIdstring

Returns

A Promise with an IntegrationResponse object.


getSites

getSites()

Gets all sites for an account.

Returns

A Promise with an array of Site.


getTeamIntegration

getTeamIntegration(teamId)

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

Parameters

NameType
teamIdstring

Returns

Returns a Promise with an IntegrationResponse object.


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.


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.


updateSiteIntegration

updateSiteIntegration(siteId, config)

Updates the integration configuration for a site.

Parameters

NameType
siteIdstring
configSiteConfiguration

Returns

An empty Promise.


updateTeamIntegration

updateTeamIntegration(teamId, config)

Updates the integration configuration for a team.

Parameters

NameType
teamIdstring
configTeamConfiguration

Returns

An empty Promise.