Integrations (webhook and Slack notifications) can be managed pragmatically using the Node.js API.
1#!/usr/bin/env node23const { Integration } = require('calibre')45const createIntegration = async () => {6 const site = 'calibre' // site slug7 const destination = 'webhook' // options: slack or webhook8 const events = ['new_snapshot'] // options: 'metric_budget_change', 'new_snapshot'9 const url = 'https://mydomain.com/webhook/' // endpoint to hit1011 // Create the integration12 const integration = await Integration.create({13 site,14 destination,15 events,16 url17 })1819 // Output the formatted JSON response20 console.log(JSON.stringify(integration, null, 2))21}2223createIntegration()
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' |
1#!/usr/bin/env node23const { Integration } = require('calibre')45const listIntegrations = async () => {6 const site = 'calibre' // site slug7 const count = 20 // number of integrations to return, maximum 50089 // List the integrations10 const integrations = await Integration.list({11 site,12 count13 })1415 // Output the formatted JSON response16 console.log(JSON.stringify(integrations, null, 2))17}1819listIntegrations()
Parameter | Required | Description |
---|---|---|
site | Yes | Site slug, found in site settings |
1#!/usr/bin/env node23const { Integration } = require('calibre')45const updateIntegration = async () => {6 const site = 'calibre' // site slug7 const uuid = '59e36fca-6307-44f2-8908-1379edf7dc60' // uuid of the integration8 const destination = 'webhook' // options: slack or webhook9 const events = ['new_snapshot'] // options: 'metric_budget_change', 'new_snapshot'10 const url = 'https://new.domain.com/webhook/' // endpoint to hit11 const isDisabled = false // true or false1213 // Update the integration14 const integration = await Integration.update({15 site,16 uuid,17 destination,18 events,19 url,20 isDisabled21 })2223 // Output the formatted JSON response24 console.log(JSON.stringify(integration, null, 2))25}2627updateIntegration()
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? |
1#!/usr/bin/env node23const { Integration } = require('calibre')45const deleteIntegration = async () => {6 const site = 'calibre' // site slug7 const uuid = '59e36fca-6307-44f2-8908-1379edf7dc60' // uuid of the integration89 // Delete the integration10 const integration = await Integration.destroy({11 site,12 uuid13 })1415 // Output the formatted JSON response16 console.log(JSON.stringify(integration, null, 2))17}1819deleteIntegration()
Parameter | Required | Description |
---|---|---|
site | Yes | Site slug, found in site settings |
uuid | Yes | The UUID of a given integration |