Skip to content

Instantly share code, notes, and snippets.

@jaredshaunsmith
Created October 25, 2021 18:09
Show Gist options
  • Save jaredshaunsmith/6f2d2b2b53573aba735f060c1280129a to your computer and use it in GitHub Desktop.
Save jaredshaunsmith/6f2d2b2b53573aba735f060c1280129a to your computer and use it in GitHub Desktop.
Figma api webhooks
// get all registered Figma webhooks
const listWebHooks = async () => {
const response = await axios({
url: `https://api.figma.com/v2/teams/${FIGMA_TEAM_ID}/webhooks`,
method: 'get',
headers: {
'X-Figma-Token': YOUR_FIGMA_PERSONAL_ACCESS_TOKEN,
}
})
return response.data.webhooks
}
// delete a specific Figma webhook
const deleteWebhook = async (hookId) => {
await axios({
url: `https://api.figma.com/v2/webhooks/${hookId}`,
method: 'delete',
headers: {
'X-Figma-Token': YOUR_FIGMA_PERSONAL_ACCESS_TOKEN,
}
})
}
// create a Figma webhook
const createFigmaWebhook = async ({
// https://www.figma.com/developers/api#webhooks-v2-events
event_type: 'FILE_VERSION_UPDATE'
}) => {
const response = await axios({
url: 'https://api.figma.com/v2/webhooks',
method: 'post',
headers: {
'X-Figma-Token': YOUR_FIGMA_PERSONAL_ACCESS_TOKEN,
},
data: {
event_type,
team_id: FIGMA_TEAM_ID,
passcode: A_SECRET_HANDSHAKE_PASSCODE_YOU_MADE_UP,
endpoint: THE_URL_THE_WEBHOOK_SHOULD_CALL
},
})
return response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment