Integrations


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

Create Integration#

Create Integrations

Node.js API
#!/usr/bin/env node

import { Integration } from 'calibre'

const createIntegration = async () => {
  const site = 'calibre' // site slug
  const destination = 'webhook' // options: slack or webhook
  const events = ['new_snapshot'] // options: 'metric_budget_change', 'new_snapshot'
  const url = 'https://mydomain.com/webhook/' // endpoint to hit

  // Create the integration
  const integration = await Integration.create({
    site,
    destination,
    events,
    url
  })

  // Output the formatted JSON response
  console.log(JSON.stringify(integration, null, 2))
}

createIntegration()

List Integrations#

Read Sites

Node.js API
#!/usr/bin/env node

import { Integration } from 'calibre'

const listIntegrations = async () => {
  const site = 'calibre' // site slug
  const count = 20 // number of integrations to return, maximum 500

  // List the integrations
  const integrations = await Integration.list({
    site,
    count
  })

  // Output the formatted JSON response
  console.log(JSON.stringify(integrations, null, 2))
}

listIntegrations()

Update Integration#

Update Integrations

Node.js API
#!/usr/bin/env node

import { Integration } from 'calibre'

const updateIntegration = async () => {
  const site = 'calibre' // site slug
  const uuid = '59e36fca-6307-44f2-8908-1379edf7dc60' // uuid of the integration
  const destination = 'webhook' // options: slack or webhook
  const events = ['new_snapshot'] // options: 'metric_budget_change', 'new_snapshot'
  const url = 'https://new.domain.com/webhook/' // endpoint to hit
  const isDisabled = false // true or false

  // Update the integration
  const integration = await Integration.update({
    site,
    uuid,
    destination,
    events,
    url,
    isDisabled
  })

  // Output the formatted JSON response
  console.log(JSON.stringify(integration, null, 2))
}

updateIntegration()

Delete Integration#

Delete Integrations

Node.js API
#!/usr/bin/env node

import { Integration } from 'calibre'

const deleteIntegration = async () => {
  const site = 'calibre' // site slug
  const uuid = '59e36fca-6307-44f2-8908-1379edf7dc60' // uuid of the integration

  // Delete the integration
  const integration = await Integration.destroy({
    site,
    uuid
  })

  // Output the formatted JSON response
  console.log(JSON.stringify(integration, null, 2))
}

deleteIntegration()

On this page