Integrations


Integrations (webhook and slack notifications) can be managed pragmatically using the Node.js API.

Create Integration

Required API Permission: Create Integrations
1#!/usr/bin/env node
2
3const { Integration } = require('calibre')
4
5const createIntegration = async () => {
6 const site = 'calibre' // site slug
7 const destination = 'webhook' // options: slack or webhook
8 const events = ['new_snapshot'] // options: 'metric_budget_change', 'new_snapshot'
9 const url = 'https://mydomain.com/webhook/' // endpoint to hit
10
11 // Create the integration
12 const integration = await Integration.create({
13 site,
14 destination,
15 events,
16 url
17 })
18
19 // Output the formatted JSON response
20 console.log(JSON.stringify(integration, null, 2))
21}
22
23createIntegration()
ParameterRequiredDescription
siteYesSite slug, found in site settings
urlYesThe URL of where the webhook will be delivered via HTTP POST as application/json
eventsYesAn array of events. Eg: ['new_snapshot']
destinationYesThe destination of this integration. Either 'slack' or 'webhook'

List Integrations

Required API Permission: Read Sites
1#!/usr/bin/env node
2
3const { Integration } = require('calibre')
4
5const listIntegrations = async () => {
6 const site = 'calibre' // site slug
7 const count = 20 // number of integrations to return, maximum 500
8
9 // List the integrations
10 const integrations = await Integration.list({
11 site,
12 count
13 })
14
15 // Output the formatted JSON response
16 console.log(JSON.stringify(integrations, null, 2))
17}
18
19listIntegrations()
ParameterRequiredDescription
siteYesSite slug, found in site settings

Update Integration

Required API Permission: Update Integrations
1#!/usr/bin/env node
2
3const { Integration } = require('calibre')
4
5const updateIntegration = async () => {
6 const site = 'calibre' // site slug
7 const uuid = '59e36fca-6307-44f2-8908-1379edf7dc60' // uuid of the integration
8 const destination = 'webhook' // options: slack or webhook
9 const events = ['new_snapshot'] // options: 'metric_budget_change', 'new_snapshot'
10 const url = 'https://new.domain.com/webhook/' // endpoint to hit
11 const isDisabled = false // true or false
12
13 // Update the integration
14 const integration = await Integration.update({
15 site,
16 uuid,
17 destination,
18 events,
19 url,
20 isDisabled
21 })
22
23 // Output the formatted JSON response
24 console.log(JSON.stringify(integration, null, 2))
25}
26
27updateIntegration()
ParameterRequiredDescription
siteYesSite slug, found in site settings
uuidYesThe UUID of a given integration
urlYesThe URL of where the webhook will be delivered via HTTP POST as application/json
eventsYesAn array of events. Eg: ['new_snapshot']
destinationYesThe destination of this integration. Either 'slack' or 'webhook'
isDisabledNoA boolean. Is this integration enabled?

Delete Integration

Required API Permission: Delete Integrations
1#!/usr/bin/env node
2
3const { Integration } = require('calibre')
4
5const deleteIntegration = async () => {
6 const site = 'calibre' // site slug
7 const uuid = '59e36fca-6307-44f2-8908-1379edf7dc60' // uuid of the integration
8
9 // Delete the integration
10 const integration = await Integration.destroy({
11 site,
12 uuid
13 })
14
15 // Output the formatted JSON response
16 console.log(JSON.stringify(integration, null, 2))
17}
18
19deleteIntegration()
ParameterRequiredDescription
siteYesSite slug, found in site settings
uuidYesThe UUID of a given integration

Related Articles