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 project or team level.
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.updateSiteConfiguration
method. This method takes theteamId
,siteId
, and theconfig
as arguments. Theconfig
is 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
To set a custom extension configuration for a team, take the following steps:
- Add an endpoint.
- Call the
client.updateTeamConfiguration
method. This method takes theteamId
and theconfig
as arguments. Theconfig
is 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
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.getSiteConfiguration
method to retrieve the custom extension configuration for a project. - Call the
client.getTeamConfiguration
method 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
Visit our API reference docs for more information about the methods and properties available to you: