How to Integrate WhatsApp API with Your CRM System
Any statistics or percentages in this article are general industry figures or illustrations, not QuackAPI measurements or promises. Results depend on your audience, consent and sending patterns. QuackAPI connects to WhatsApp as a linked device (an unofficial method), so read our risk and acceptable use policy before sending.
Why Integrate WhatsApp with Your CRM
Integrating WhatsApp with your CRM creates a unified view of customer interactions. Sales and support teams can see complete conversation histories alongside deal stages, tickets, and contact information.
Automated WhatsApp messages triggered by CRM events like deal stage changes, ticket updates, or follow-up reminders ensure timely and consistent customer communication without manual effort.
Architecture Overview
The integration works in two directions. Inbound: QuackAPI webhooks forward incoming WhatsApp messages to your server, which then creates or updates CRM records. Outbound: CRM events trigger your server to send WhatsApp messages through the QuackAPI API.
Your server acts as a middleware layer between QuackAPI and your CRM. This gives you full control over data transformation, filtering, and business logic before data flows in either direction.
Using Webhooks for CRM Sync
Set up a webhook endpoint to receive incoming WhatsApp messages and sync them to your CRM. The following example receives messages and creates a new contact or updates conversation history in your CRM.
const express = require("express");
const axios = require("axios");
const app = express();
app.use(express.json());
const CRM_API_URL = "https://api.your-crm.com";
const CRM_API_KEY = process.env.CRM_API_KEY;
app.post("/webhook/whatsapp", async (req, res) => {
const { event, from, message, deviceId } = req.body;
if (event === "message.received") {
try {
// Search for existing contact in CRM
let contact = await findCRMContact(from);
if (!contact) {
// Create new contact
contact = await createCRMContact(from);
}
// Log the conversation in CRM
await logConversation(contact.id, {
direction: "inbound",
channel: "whatsapp",
content: message.content,
timestamp: new Date().toISOString()
});
} catch (error) {
console.error("CRM sync failed:", error.message);
}
}
res.status(200).json({ received: true });
});
async function findCRMContact(phone) {
const { data } = await axios.get(
`${CRM_API_URL}/contacts/search?phone=${phone}`,
{ headers: { "Authorization": `Bearer ${CRM_API_KEY}` } }
);
return data.results[0] || null;
}
async function createCRMContact(phone) {
const { data } = await axios.post(
`${CRM_API_URL}/contacts`,
{ phone, source: "whatsapp" },
{ headers: { "Authorization": `Bearer ${CRM_API_KEY}` } }
);
return data;
}
async function logConversation(contactId, entry) {
await axios.post(
`${CRM_API_URL}/contacts/${contactId}/conversations`,
entry,
{ headers: { "Authorization": `Bearer ${CRM_API_KEY}` } }
);
}Sending CRM-Triggered Messages
Trigger WhatsApp messages from CRM events such as deal stage changes, appointment reminders, or follow-up tasks. Use CRM webhooks or polling to detect events and send messages via the QuackAPI API.
const QUACKAPI_URL = "https://quackapi.com/v1/messages/send";
const QUACKAPI_API_KEY = process.env.QUACKAPI_API_KEY;
// CRM webhook: deal stage changed
app.post("/crm/webhook/deal-update", async (req, res) => {
const { dealId, stage, contact } = req.body;
const messages = {
"proposal_sent": "Hi! We have sent you a proposal. Please review and let us know if you have any questions.",
"won": "Congratulations! Your order has been confirmed. We will begin processing it right away.",
"follow_up": "Hi! Just checking in. Do you have any questions about our proposal?"
};
const messageText = messages[stage];
if (messageText && contact.phone) {
try {
await axios.post(QUACKAPI_URL, {
deviceId: 1,
to: contact.phone,
content: messageText,
type: "text"
}, {
headers: {
"Content-Type": "application/json",
"x-api-key": QUACKAPI_API_KEY
}
});
console.log(`Sent ${stage} message to ${contact.phone}`);
} catch (error) {
console.error("Failed to send CRM message:", error.message);
}
}
res.status(200).json({ processed: true });
});Popular CRM Integrations
HubSpot: Use the HubSpot CRM API to create contacts, log engagements, and track deals. HubSpot supports custom properties where you can store the WhatsApp number and conversation metadata. Use HubSpot webhooks to trigger outbound messages on deal stage changes.
Salesforce: Leverage the Salesforce REST API to sync WhatsApp conversations as Activity records. Map WhatsApp contacts to Salesforce Leads or Contacts. Use Salesforce Process Builder or Flow to trigger WhatsApp notifications on record updates.
Zoho CRM: The Zoho CRM API supports contact management and custom modules where you can store WhatsApp conversation logs. Use Zoho's workflow rules to trigger API calls to your middleware when CRM events occur.
Building a Custom Integration
For CRMs without built-in integrations, build a custom middleware service. Define a standard interface for CRM operations like contact lookup, creation, and conversation logging. Implement this interface for each CRM you need to support.
Use a message queue like Redis or RabbitMQ to decouple webhook processing from CRM API calls. This ensures webhook responses are fast and CRM sync happens reliably even if the CRM API is temporarily slow or unavailable.
Test your integration thoroughly with realistic data volumes. Implement retry logic for failed CRM API calls and set up monitoring to detect sync failures early.