Skip to main content

Unified chat

Base URL https://api.leadx.in/api/key/protected. Every request needs an apikey header — see Authentication.

3 endpoints.

GET /unified-chat​

List contacts that have conversation history.

Auth apikey

:::note Used by the web app pages/UnifiedChat.jsx :::

Query parameters — the standard list contract: p, n, sortBy, sortOrder, searchBy, searchValue, filters, advancedFilters, ids, nids. See Pagination and Filtering.

Response — data is one UnifiedMessage object.

cURL
curl -X GET 'https://api.leadx.in/api/key/protected/unified-chat?p=1&n=25' \
-H 'apikey: $LEADX_API_KEY'
fetch
// Node 18+ and every modern browser ship fetch.
const res = await fetch('https://api.leadx.in/api/key/protected/unified-chat?p=1&n=25', {
method: 'GET',
headers: {
apikey: process.env.LEADX_API_KEY,
},
});

const payload = await res.json();
if (!res.ok) {
// Errors carry { status, success, message } — not the success envelope.
throw new Error(`${res.status} ${payload.message}`);
}

console.log(payload.data);
axios
import axios from 'axios';

const leadx = axios.create({
baseURL: 'https://api.leadx.in/api/key/protected',
headers: { apikey: process.env.LEADX_API_KEY },
});

try {
const { data } = await leadx.get(
'/unified-chat?p=1&n=25'
);
console.log(data.data);
} catch (err) {
// axios throws on 4xx/5xx; the envelope is on err.response.data.
throw new Error(`${err.response?.status} ${err.response?.data?.message ?? err.message}`);
}
Node (no deps)
import { request } from 'node:https';

// The dependency-free version, for somewhere fetch is not available.
const send = (payload) =>
new Promise((resolve, reject) => {
const req = request(
'https://api.leadx.in/api/key/protected/unified-chat?p=1&n=25',
{
method: 'GET',
headers: {
apikey: process.env.LEADX_API_KEY,
},
},
(res) => {
let raw = '';
res.on('data', (chunk) => { raw += chunk; });
res.on('end', () => {
const body = JSON.parse(raw);
if (res.statusCode >= 400) reject(new Error(`${res.statusCode} ${body.message}`));
else resolve(body);
});
},
);
req.on('error', reject);

req.end();
});

const { data } = await send(null);
console.log(data);
Python
import os
import requests

res = requests.get(
"https://api.leadx.in/api/key/protected/unified-chat?p=1&n=25",
headers={"apikey": os.environ["LEADX_API_KEY"]},
timeout=30,
)

payload = res.json()
res.raise_for_status()
print(payload["data"])
PHP
<?php
$ch = curl_init('https://api.leadx.in/api/key/protected/unified-chat?p=1&n=25');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'apikey: ' . getenv('LEADX_API_KEY'),
],
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$payload = json_decode($response, true);
if ($status >= 400) {
throw new RuntimeException("$status {$payload['message']}");
}

print_r($payload['data']);

GET /unified-chat/messages​

List messages in a conversation.

Auth apikey

:::note Used by the web app components/ChatWindow.jsx, components/EmailMessageSend.jsx, components/WhatsappMessageSend.jsx :::

cURL
curl -X GET 'https://api.leadx.in/api/key/protected/unified-chat/messages' \
-H 'apikey: $LEADX_API_KEY'
fetch
// Node 18+ and every modern browser ship fetch.
const res = await fetch('https://api.leadx.in/api/key/protected/unified-chat/messages', {
method: 'GET',
headers: {
apikey: process.env.LEADX_API_KEY,
},
});

const payload = await res.json();
if (!res.ok) {
// Errors carry { status, success, message } — not the success envelope.
throw new Error(`${res.status} ${payload.message}`);
}

console.log(payload.data);
axios
import axios from 'axios';

const leadx = axios.create({
baseURL: 'https://api.leadx.in/api/key/protected',
headers: { apikey: process.env.LEADX_API_KEY },
});

try {
const { data } = await leadx.get(
'/unified-chat/messages'
);
console.log(data.data);
} catch (err) {
// axios throws on 4xx/5xx; the envelope is on err.response.data.
throw new Error(`${err.response?.status} ${err.response?.data?.message ?? err.message}`);
}
Node (no deps)
import { request } from 'node:https';

// The dependency-free version, for somewhere fetch is not available.
const send = (payload) =>
new Promise((resolve, reject) => {
const req = request(
'https://api.leadx.in/api/key/protected/unified-chat/messages',
{
method: 'GET',
headers: {
apikey: process.env.LEADX_API_KEY,
},
},
(res) => {
let raw = '';
res.on('data', (chunk) => { raw += chunk; });
res.on('end', () => {
const body = JSON.parse(raw);
if (res.statusCode >= 400) reject(new Error(`${res.statusCode} ${body.message}`));
else resolve(body);
});
},
);
req.on('error', reject);

req.end();
});

const { data } = await send(null);
console.log(data);
Python
import os
import requests

res = requests.get(
"https://api.leadx.in/api/key/protected/unified-chat/messages",
headers={"apikey": os.environ["LEADX_API_KEY"]},
timeout=30,
)

payload = res.json()
res.raise_for_status()
print(payload["data"])
PHP
<?php
$ch = curl_init('https://api.leadx.in/api/key/protected/unified-chat/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'apikey: ' . getenv('LEADX_API_KEY'),
],
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$payload = json_decode($response, true);
if ($status >= 400) {
throw new RuntimeException("$status {$payload['message']}");
}

print_r($payload['data']);

POST /unified-chat/messages​

Send a one-to-one message on any channel.

Auth apikey

:::note Used by the web app components/ChatWindow.jsx, components/EmailMessageSend.jsx, components/WhatsappMessageSend.jsx :::

Prerequisites

  1. A connected app for the channel named in mode. POST /apps/whatsapp · POST /apps/instagram · GET /apps/smtp
  2. A contact to send to (or recipientId for Instagram). POST /contact

Request body

FieldTypeDefaultNotes
contactObjectId -> Contact—Contact id. Required for every mode except instagram.
messageTypestringmessage
content—Object, or a plain string for Instagram. Pass a template as content.template.
recipient_typestringindividual
modestringwhatsappwhatsapp, instagram, smtp/email, or webchat. An unknown mode is a 400.
app—Which connected app sends, when you have several.
appType—
recipientId—Instagram-scoped user id, used instead of contact.
senderId—Specific sending identity.
leadId—Attach the message to a lead's timeline.
scheduled—Send later rather than now.
scheduledAtdate—ISO timestamp, with scheduled.
contactSpecificMessageboolean—Per-contact override text.

Response — data is one UnifiedMessage object.

cURL
curl -X POST 'https://api.leadx.in/api/key/protected/unified-chat/messages' \
-H 'apikey: $LEADX_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"contact": "",
"messageType": "message",
"content": "",
"recipient_type": "individual",
"mode": "whatsapp",
"app": "",
"appType": "",
"recipientId": "",
"senderId": "",
"leadId": "",
"scheduled": "",
"scheduledAt": "",
"contactSpecificMessage": ""
}'
fetch
// Node 18+ and every modern browser ship fetch.
const res = await fetch('https://api.leadx.in/api/key/protected/unified-chat/messages', {
method: 'POST',
headers: {
apikey: process.env.LEADX_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"contact": "",
"messageType": "message",
"content": "",
"recipient_type": "individual",
"mode": "whatsapp",
"app": "",
"appType": "",
"recipientId": "",
"senderId": "",
"leadId": "",
"scheduled": "",
"scheduledAt": "",
"contactSpecificMessage": ""
}),
});

const payload = await res.json();
if (!res.ok) {
// Errors carry { status, success, message } — not the success envelope.
throw new Error(`${res.status} ${payload.message}`);
}

console.log(payload.data);
axios
import axios from 'axios';

const leadx = axios.create({
baseURL: 'https://api.leadx.in/api/key/protected',
headers: { apikey: process.env.LEADX_API_KEY },
});

try {
const { data } = await leadx.post(
'/unified-chat/messages',
{
"contact": "",
"messageType": "message",
"content": "",
"recipient_type": "individual",
"mode": "whatsapp",
"app": "",
"appType": "",
"recipientId": "",
"senderId": "",
"leadId": "",
"scheduled": "",
"scheduledAt": "",
"contactSpecificMessage": ""
}
);
console.log(data.data);
} catch (err) {
// axios throws on 4xx/5xx; the envelope is on err.response.data.
throw new Error(`${err.response?.status} ${err.response?.data?.message ?? err.message}`);
}
Node (no deps)
import { request } from 'node:https';

// The dependency-free version, for somewhere fetch is not available.
const send = (payload) =>
new Promise((resolve, reject) => {
const req = request(
'https://api.leadx.in/api/key/protected/unified-chat/messages',
{
method: 'POST',
headers: {
apikey: process.env.LEADX_API_KEY,
'Content-Type': 'application/json',
},
},
(res) => {
let raw = '';
res.on('data', (chunk) => { raw += chunk; });
res.on('end', () => {
const body = JSON.parse(raw);
if (res.statusCode >= 400) reject(new Error(`${res.statusCode} ${body.message}`));
else resolve(body);
});
},
);
req.on('error', reject);
req.write(JSON.stringify(payload));
req.end();
});

const { data } = await send({
"contact": "",
"messageType": "message",
"content": "",
"recipient_type": "individual",
"mode": "whatsapp",
"app": "",
"appType": "",
"recipientId": "",
"senderId": "",
"leadId": "",
"scheduled": "",
"scheduledAt": "",
"contactSpecificMessage": ""
});
console.log(data);
Python
import os
import requests

res = requests.post(
"https://api.leadx.in/api/key/protected/unified-chat/messages",
headers={"apikey": os.environ["LEADX_API_KEY"]},
json={
"contact": "",
"messageType": "message",
"content": "",
"recipient_type": "individual",
"mode": "whatsapp",
"app": "",
"appType": "",
"recipientId": "",
"senderId": "",
"leadId": "",
"scheduled": "",
"scheduledAt": "",
"contactSpecificMessage": ""
},
timeout=30,
)

payload = res.json()
res.raise_for_status()
print(payload["data"])
PHP
<?php
$ch = curl_init('https://api.leadx.in/api/key/protected/unified-chat/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'apikey: ' . getenv('LEADX_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode({
'contact': '',
'messageType': 'message',
'content': '',
'recipient_type': 'individual',
'mode': 'whatsapp',
'app': '',
'appType': '',
'recipientId': '',
'senderId': '',
'leadId': '',
'scheduled': '',
'scheduledAt': '',
'contactSpecificMessage': ''
}),
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$payload = json_decode($response, true);
if ($status >= 400) {
throw new RuntimeException("$status {$payload['message']}");
}

print_r($payload['data']);