Skip to content

Use cases for endpoints

One of the benefits of adding endpoints to your extension is that you can use them with Netlify’s Extension API to integrate with Netlify. This page highlights some examples.

Use a custom extension configuration

The Extension API allows you to set a custom extension configuration. This configuration is a JSON object that can be used to store any data you want on either a site or team level.

Set a custom extension configuration for a site

To set a custom extension configuration for a site, take the following steps:

  1. Add an endpoint.
  2. Call the client.updateSiteConfiguration method. This method takes the teamId, siteId, and the config as arguments. The config is a JSON object that can contain any data you want.
src/endpoints/my-function.ts
import { withNetlifySDKContext } from "@netlify/sdk/ui/functions";
export default withNetlifySDKContext(async (req, context) => {
const { client, siteId, teamId } = context;
await client.updateSiteConfiguration(teamId, siteId, {
custom_field: "custom_value",
});
return Response.json({});
});

Set a custom extension configuration for a team

To set a custom extension configuration for a team, take the following steps:

  1. Add an endpoint.
  2. Call the client.updateTeamConfiguration method. This method takes the teamId and the config as arguments. The config is a JSON object that can contain any data you want.
src/endpoints/my-function.ts
import { withNetlifySDKContext } from "@netlify/sdk/ui/functions";
export default withNetlifySDKContext(async (req, context) => {
const { client, teamId } = context;
await client.updateTeamConfiguration(teamId, {
custom_field: "custom_value",
});
return Response.json({});
});

Retrieve a custom extension configuration for a site or team

After setting a custom extension configuration for a site or a team, you can retrieve it by taking the following steps:

  1. Add an endpoint.
  2. Call the client.getSiteConfiguration method to retrieve the custom extension configuration for a site.
  3. Call the client.getTeamConfiguration method to retrieve the custom extension configuration for a team.
src/endpoints/my-function.ts
import { withNetlifySDKContext } from "@netlify/sdk/ui/functions";
export default withNetlifySDKContext(async (req, context) => {
const { client, teamId, siteId } = context;
// This retrieves the custom extension configuration for the site with the given siteId
const { custom_field } = await client.getSiteConfiguration(siteId);
// This retrieves the custom extension configuration for the team with the given teamId
const { custom_field } = await client.getTeamConfiguration(teamId);
return Response.json({});
});

More resources

Visit our API reference docs for more information about the methods and properties available to you:

Got it!

Your feedback helps us improve our docs.