Disconnect a mailbox
Remove a mailbox and its stored credentials, pause the campaigns that use it first, and confirm it is gone.
For AI agents: the docs index is at /llms.txt, and every page is also served as markdown at its URL plus .md.
#What you need
- A key with write scope. Disconnecting changes state, so a read key gets
403 forbidden. See Authentication. - The mailbox id from
GET /v1/mailboxes.
Disconnecting cannot be undone. The stored credentials are deleted, and the mailbox has to be connected again from the start to be used again.
#Find the campaigns that use it
Each campaign lists the mailboxes it rotates across in mailbox_ids. GET /v1/campaigns returns them a page at a time, so page through and keep the campaigns whose mailbox_ids contain your mailbox id.
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };
async function call(method, path, body) {
const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
const json = await res.json();
if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
return json;
}
const mailboxId = process.env.MAILBOX_ID;
const using = [];
let cursor;
do {
const query = new URLSearchParams({ limit: '200', ...(cursor ? { cursor } : {}) });
const page = await call('GET', `/v1/campaigns?${query}`);
using.push(...page.data.filter((c) => c.mailbox_ids.includes(mailboxId)));
cursor = page.next_cursor ?? undefined;
} while (cursor);
console.log(using.map((c) => [c.id, c.name, c.status]));#Pause or re-route those campaigns
Deleting the mailbox drops it from every campaign rotation. To keep control of what sends, deal with each active campaign first. There are two ways.
POST /v1/campaigns/{id}/pausestops further sends from the campaign at the next send cycle. Leads keep their place in the sequence. Pausing a paused campaign succeeds and changes nothing; a campaign that has not started or is completed cannot be paused.PATCH /v1/campaigns/{id}withmailbox_idsreplaces the whole rotation set, so send the full list of mailboxes you want to keep. It takes effect on the next send cycle, also for an active campaign.
# Pause one campaign
curl -X POST https://api.coldagentai.com/v1/campaigns/$CAMPAIGN_ID/pause \
-H "Authorization: Bearer $COLDAGENTAI_API_KEY"
# Or give it a different set of mailboxes
curl -X PATCH https://api.coldagentai.com/v1/campaigns/$CAMPAIGN_ID \
-H "Authorization: Bearer $COLDAGENTAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "mailbox_ids": ["mbx_keep_1", "mbx_keep_2"] }'const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };
async function call(method, path, body) {
const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
const json = await res.json();
if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
return json;
}
for (const campaign of using) {
if (campaign.status === 'active') await call('POST', `/v1/campaigns/${campaign.id}/pause`);
}Starting a campaign again is refused until it has at least one connected mailbox, so a paused campaign whose only mailbox was removed needs a new mailbox in mailbox_ids before POST /v1/campaigns/{id}/start works.
#Disconnect the mailbox
DELETE /v1/mailboxes/{id} removes the mailbox and its stored credentials and drops it from campaign rotations. It takes no body. The response is the id and deleted: true.
curl -X DELETE https://api.coldagentai.com/v1/mailboxes/$MAILBOX_ID \
-H "Authorization: Bearer $COLDAGENTAI_API_KEY"const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };
async function call(method, path, body) {
const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
const json = await res.json();
if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
return json;
}
const removed = await call('DELETE', `/v1/mailboxes/${process.env.MAILBOX_ID}`);
console.log(removed);#Confirm it is gone
GET /v1/mailboxes/{id}now answers 404 withunknown_product.GET /v1/mailboxesno longer lists it.- Each campaign you looked at earlier no longer has the id in
mailbox_ids.
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };
async function call(method, path, body) {
const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
const json = await res.json();
if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
return json;
}
const res = await fetch(`${base}/v1/mailboxes/${process.env.MAILBOX_ID}`, { headers });
console.log(res.status); // 404 once the mailbox is gone#What disconnecting does not do
- It does not contact the mail provider. The route deletes what ColdAgentAI stores. To withdraw the access you granted, remove it in the settings of the Google, Microsoft or other mail account itself.
- It does not pause campaigns for you, and it does not delete campaigns, sequences or leads.
- It does not delete mail already sent or received, and it does not touch the domain or its DNS records.
- It does not give the mailbox back later. Connect it again with
POST /v1/mailboxesfor IMAP and SMTP, orPOST /v1/mailboxes/gmail/connectthenPOST /v1/mailboxes/gmail/complete(microsoftin place ofgmailfor Microsoft 365) for the OAuth flows.
#What can go wrong
| Code | Cause | Fix |
|---|---|---|
unknown_product | The mailbox id is not in your account, or it was already deleted. | List mailboxes with GET /v1/mailboxes. |
forbidden | The key has read scope. | Use a write key. |
invalid_input | You tried to pause a campaign that has not started or is completed. | Skip it: only an active campaign needs pausing. |
rate_limited | Too many requests for this key. | Wait Retry-After seconds. |