Back

Quick Guide to Implementing Webhooks in ConnectWise Manage

Aug 16, 20246 minute read

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!

What's the Deal with Webhooks?

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!

Before We Start

Make sure you've got:

  • A ConnectWise Manage account with API access (you're cool like that)
  • Node.js installed on your machine
  • A basic grasp of RESTful APIs (but you knew that already, right?)

Setting Up Shop

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

Shaking Hands with the API

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); }

Crafting Your Webhook

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();

Choosing Your Events

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'] }

Catching Those Webhooks

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'));

Taking It for a Spin

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.

Pro Tips

  • Always validate that the webhook is coming from ConnectWise Manage. You could use a shared secret or check the IP address.
  • Implement proper error handling and maybe even a retry mechanism for those "just in case" moments.
  • Keep an eye on those rate limits. ConnectWise Manage isn't shy about throttling if you get too eager.

Wrapping Up

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! 🚀