Integrations Integrations (webhook and Slack notifications) can be managed pragmatically using the Node.js API.
Required API Permission: Create Integrations
Copy Code
1 #!/usr/bin/env node
2
3 import { Integration } from 'calibre'
4
5 const 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
23 createIntegration ( )
Parameter Required Description site Yes Site slug, found in site settings url Yes The URL of where the webhook will be delivered via HTTP POST as application/json events Yes An array of events. Eg: ['new_snapshot'] destination Yes The destination of this integration. Either 'slack' or 'webhook'
Required API Permission: Read Sites
Copy Code
1 #!/usr/bin/env node
2
3 import { Integration } from 'calibre'
4
5 const 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
19 listIntegrations ( )
Parameter Required Description site Yes Site slug, found in site settings
Required API Permission: Update Integrations
Copy Code
1 #!/usr/bin/env node
2
3 import { Integration } from 'calibre'
4
5 const 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
27 updateIntegration ( )
Parameter Required Description site Yes Site slug, found in site settings uuid Yes The UUID of a given integration url Yes The URL of where the webhook will be delivered via HTTP POST as application/json events Yes An array of events. Eg: ['new_snapshot'] destination Yes The destination of this integration. Either 'slack' or 'webhook' isDisabled No A boolean. Is this integration enabled?
Required API Permission: Delete Integrations
Copy Code
1 #!/usr/bin/env node
2
3 import { Integration } from 'calibre'
4
5 const 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
19 deleteIntegration ( )
Parameter Required Description site Yes Site slug, found in site settings uuid Yes The UUID of a given integration