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
Section titled “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 project or team level.
Set a custom extension configuration for a project
Section titled “Set a custom extension configuration for a project”To set a custom extension configuration for a project, take the following steps:
- Add an endpoint.
- Call the
client.updateSiteConfigurationmethod. This method takes theteamId,siteId, and theconfigas arguments. Theconfigis a JSON object that can contain any data you want.
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
Section titled “Set a custom extension configuration for a team”To set a custom extension configuration for a team, take the following steps:
- Add an endpoint.
- Call the
client.updateTeamConfigurationmethod. This method takes theteamIdand theconfigas arguments. Theconfigis a JSON object that can contain any data you want.
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 project or team
Section titled “Retrieve a custom extension configuration for a project or team”After setting a custom extension configuration for a project or a team, you can retrieve it by taking the following steps:
- Add an endpoint.
- Call the
client.getSiteConfigurationmethod to retrieve the custom extension configuration for a project. - Call the
client.getTeamConfigurationmethod to retrieve the custom extension configuration for a team.
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 project 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
Section titled “More resources”Visit our API reference docs for more information about the methods and properties available to you: