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 } = context;
const accountInfo = await client.getAccount(accountId);
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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
key | string |
values | EnvironmentVariableValue [] |
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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
key | string |
value | EnvVarRequest |
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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
variables | Record<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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
key | string |
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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
variables | string [] |
Returns
An empty Promise
.
disableBuildEventHandlers
disableBuildEventHandlers(siteId)
Disables the build event handlers for a site.
Parameters
Name | Type |
---|---|
siteId | string |
Returns
An empty Promise
.
disableSiteIntegration
disableSiteIntegration(siteId)
Disables this integration for a site, which also deletes the configuration.
Parameters
Name | Type |
---|---|
siteId | string |
Returns
An empty Promise
.
disableTeamIntegration
disableTeamIntegration(teamId)
Disables this integration for a team, which also deletes the configuration.
Parameters
Name | Type |
---|---|
teamId | string |
Returns
An empty Promise
.
enableBuildEventHandlers
enableBuildEventHandlers(siteId)
Enables the build event handlers for a site.
Parameters
Name | Type |
---|---|
siteId | string |
Returns
An empty Promise
.
enableConnectors
enableConnectors(teamId)
Enables the connector for a team.
Parameters
Name | Type |
---|---|
teamId | string |
Returns
An empty Promise
.
enableSiteIntegration
enableSiteIntegration(siteId, config)
Enables this integration for a site, passing a configuration object.
Parameters
Name | Type |
---|---|
siteId | string |
config | object |
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
Name | Type |
---|---|
teamId | string |
config | object |
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
Name | Type |
---|---|
siteId | string |
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
Name | Type |
---|---|
siteId | string |
teamId? | string |
Returns
A Promise
with a { token: string }
object.
getAccount
getAccount(accountId)
Gets an account by ID and returns account information.
Parameters
Name | Type |
---|---|
accountId | string |
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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
Returns
A Promise
with an array of EnvironmentVariable
.
getSite
getSite(siteId)
Gets a site by ID and returns site information.
Parameters
Name | Type |
---|---|
siteId | string |
Returns
A Promise
with a Site
.
getSiteIntegration
getSiteIntegration(siteId)
Returns the integration configuration for a site for the current integration.
Parameters
Name | Type |
---|---|
siteId | string |
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
Name | Type |
---|---|
teamId | string |
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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
key | string |
context | string |
value | string |
contextParameter | string optional |
Returns
A Promise
with an EnvironmentVariable
object.
removeBuildToken
removeBuildToken(accountId, siteId)
Removes the build token for a site.
Parameters
Name | Type |
---|---|
accountId | string |
siteId | string |
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
Name | Type |
---|---|
accountId | string |
siteId | string |
token | string |
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
Name | Type |
---|---|
accountId | string |
siteId | string optional |
key | string |
values | EnvironmentVariableValue [] |
Returns
A Promise
with an EnvironmentVariable
object.
updateSite
updateSite(siteId, changes?)
Updates a site with the given changes.
Parameters
Name | Type |
---|---|
siteId | string |
changes | Partial <Site > |
Returns
A Promise
with a Site
object.
updateSiteIntegration
updateSiteIntegration(siteId, config)
Updates the integration configuration for a site.
Parameters
Name | Type |
---|---|
siteId | string |
config | SiteConfiguration |
Returns
An empty Promise
.
updateTeamIntegration
updateTeamIntegration(teamId, config)
Updates the integration configuration for a team.
Parameters
Name | Type |
---|---|
teamId | string |
config | TeamConfiguration |
Returns
An empty Promise
.