Last active
August 15, 2018 14:20
-
-
Save C-Saunders/0a69d8103384d79b79ee4f30175c4edd to your computer and use it in GitHub Desktop.
StatusCake - add contact group to multiple tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { StatusCake, getTests, getContactGroups, updateTest } = require('statuscakejs') | |
const uniq = require('lodash.uniq') | |
// get these from Account > User Details | |
const statusCake = new StatusCake('username', 'apiKey') | |
let allTests | |
getTests(statusCake).then(data => allTests = data) | |
let allContacts | |
getContactGroups(statusCake).then(data => allContacts = data) | |
// find contact(s) to update | |
let person = allContacts.filter(c => c.GroupName === 'Person Name')[0] | |
// find tests to update | |
let toUpdate = allTests.filter(t => /maybe|use|a|regex/i.test(t.WebsiteName)) | |
// you may want to check this list against the requested list with something like | |
toUpdate.map(t => t.WebsiteName).sort() | |
// do updates | |
toUpdate.forEach(account => updateTest(statusCake, { TestID: account.TestID, ContactGroup: (uniq(account.ContactGroup.concat(person.ContactID))).join(',') }).then(console.log)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment