Created
October 12, 2020 16:07
-
-
Save icelander/019fb04eac49c69c4c0eaa03757dd72c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'smartsheet' | |
webhook_url = "https://mattermost.example.com/hooks/yu6twumt93n89cjibmhdgz6mpa" | |
smartsheet_api_key = "<SMARTSHEET API KEY>" | |
smartsheet_id = "<SMARTSHEET ID>" # File > Properties on sheet | |
# Initialize the client - use your access token here | |
smartsheet_client = Smartsheet::Client.new(token: smartsheet_api_key) | |
# The `smartsheet_client` variable now contains access to all of the APIs | |
begin | |
# This creates a webhook that fires when a column is updated | |
mattermost_webhook = { | |
name: "Mattermost", | |
callbackUrl: webhook_url, | |
scope: "sheet", | |
scopeObjectId: smartsheet_id, | |
events: ["*.*"], | |
version: 1, | |
subscope: { | |
columnIds: [4912585878333316], # Be sure to replace this value | |
} | |
} | |
hook = smartsheet_client.webhooks.create(body: mattermost_webhook) | |
smartsheet_client.webhooks.update(webhook_id: hook['id'], body: {enabled: true}) | |
rescue Smartsheet::ApiError => e | |
puts "Error Code: #{e.error_code}" | |
puts "Message: #{e.message}" | |
puts "Ref Id: #{e.ref_id}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment