Hey there, fellow Javascript devs! Ready to supercharge your ConnectWise Manage integration with webhooks? Let's dive right in and get those real-time updates flowing!
Webhooks are like your app's personal news reporters, delivering the latest updates from ConnectWise Manage straight to your doorstep. They're crucial for keeping your integration snappy and up-to-date. We'll be using the ConnectWise Manage API to set these up, so buckle up!
Make sure you've got:
First things first, let's get our environment ready:
npm init -y npm install axios express dotenv
Create a .env
file for your API creds:
CW_COMPANY_ID=your_company_id
CW_PUBLIC_KEY=your_public_key
CW_PRIVATE_KEY=your_private_key
CW_API_URL=https://api-na.myconnectwise.net/v4_6_release/apis/3.0
Let's create a quick function to get that auth header:
require('dotenv').config(); const btoa = require('btoa'); function getAuthHeader() { const companyId = process.env.CW_COMPANY_ID; const publicKey = process.env.CW_PUBLIC_KEY; const privateKey = process.env.CW_PRIVATE_KEY; const combined = companyId + '+' + publicKey + ':' + privateKey; return 'Basic ' + btoa(combined); }
Now for the fun part - creating the webhook:
const axios = require('axios'); async function createWebhook() { try { const response = await axios.post( `${process.env.CW_API_URL}/system/callbacks`, { url: 'https://your-app.com/webhook', type: 'callback', level: 'owner', description: 'My awesome webhook' }, { headers: { 'Authorization': getAuthHeader(), 'Content-Type': 'application/json' } } ); console.log('Webhook created:', response.data); } catch (error) { console.error('Error creating webhook:', error.response.data); } } createWebhook();
When creating your webhook, you can specify which events you're interested in. Here's a taste of what's available:
ActivityCreated
TicketUpdated
ProjectCreated
Just add an events
array to your webhook creation payload:
{ // ... other webhook details events: ['TicketUpdated', 'ProjectCreated'] }
Let's set up a simple Express server to catch those incoming webhooks:
const express = require('express'); const app = express(); app.use(express.json()); app.post('/webhook', (req, res) => { console.log('Received webhook:', req.body); // Do something awesome with the data res.sendStatus(200); }); app.listen(3000, () => console.log('Webhook server running on port 3000'));
ConnectWise Manage has a nifty test feature. Head to Setup > Integrator Login > API Members, find your callback, and hit that "Test" button. If everything's set up right, you should see the payload in your console.
And there you have it! You're now equipped to implement webhooks in ConnectWise Manage like a pro. Remember, practice makes perfect, so don't be afraid to experiment and push the boundaries of what you can do with real-time data.
Want to see a full working example? Check out our GitHub repo for the complete code.
Now go forth and webhook all the things! 🚀