RevTrails Documentation
RevTrails records what your leads do on your website and what your systems do to them, in one trail per lead. Everything is a JSON API call, built for the agents and systems that work your leads.
Overview
RevTrails keeps three things for every lead, and hands each back in one call:
- The lead record: an ID, a stage, when it is next due for work, and any fields you want to keep.
- The events: everything that happened, oldest first. Page views, time on page, clicks and form submissions from your site; emails sent, opened, replied to and bounced; purchases; every change to the lead. A visitor's anonymous visits join their trail once they become a lead.
- The trail: the content. Every email sent and received in full, every form submission, notes, call transcripts and documents, with the text extracted from each document.
RevTrails never decides anything for you. It records what happened and gives it back, so your own agent or process can decide what a lead should see next.
There are three ways in:
| Routes | Called by | Authentication |
|---|---|---|
/rt/* |
The RevTrails script on your pages, through your own domain | None: the browser talks only to your site |
/v1/* |
Your servers, agents and tools, at https://api.revtrails.com |
Your API key |
/mcp |
Your AI assistant: Claude, ChatGPT or any assistant that connects to MCP servers | You sign in once with your API key |
Quickstart
When your account is set up, your site's /rt/ path is connected to RevTrails and you have an API key. From there:
1. Add the script to every page you want counted, in the <head>:
<script src="/rt/w.js" defer></script>
2. Visit a page in a normal browser, scroll, and stay a few seconds.
3. Read today's numbers:
curl -s "https://api.revtrails.com/v1/stats/period?period=day&start=2026-11-27" \ -H "x-api-key: YOUR_API_KEY"
4. Create a lead and read it back:
curl -s -X POST https://api.revtrails.com/v1/leads \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{"stage": "new", "metadata": {"email": "jane@acme.com", "company": "Acme"}}' curl -s https://api.revtrails.com/v1/leads/LEAD_ID/events \ -H "x-api-key: YOUR_API_KEY"
That's the whole integration: a script tag on your pages and an API key on your servers.
Authentication
Every /v1/* request carries your API key in the x-api-key header. The key identifies your account, so there is no account ID to send.
x-api-key: YOUR_API_KEY Content-Type: application/json
A key is either a write key or a read-only key. A read-only key works on every GET route and answers 403 Read-only key on anything that writes: give one to an agent that only needs to read.
Keep your API key secret. Never put it in a page, a browser script or a public repository. Give each system or agent its own key, so one can be replaced without touching the others. Keys are issued and revoked by us: contact us.
Core Concepts
| Concept | What it is |
|---|---|
| Lead | One person you work. Its ID is a ULID. It has a stage (your own code, such as new or qualified), a dueAt time, an assignedTo (who works it, in your own words: a person, a team or a role), and metadata: any JSON you want to keep on it. RevTrails reads none of your metadata except the fields you name in your search schema. |
| Visitor | A browser on your site, known by a first-party cookie that lasts 400 days. A visitor who submits a form becomes a lead with the visitor's ID as the lead ID. A lead who follows a tracked link from one of your emails is joined to that browser, and the visits it made before join the lead's events. |
| Event | A fact with a type and a time: web_view, email_send, crm_stage and so on (see Event Types). Events are never changed. |
| Trail entry | Content kept on a lead: an email, a form submission, a note, a document or a merge record. Each has a short header and a body; list the headers, then read only the bodies you need. |
| Session | A visit: a visitor's events with no gap of more than 30 minutes. |
| Pixel | A tracking image made for one email to one lead, before it is sent. It records opens and ties clicks, replies and bounces to that send. |
| Page ID, audience ID, template | Your own ULIDs, carried on events so you can count by them: nodeId names a page or step in your sequence, audienceId the audience a send goes to, the group a request to stop applies to, templateId and templateVersion (1.4.0) the email that was sent. |
| Suppression lists | Addresses that asked to stop, reported spam or bounced. RevTrails refuses a tracked send to them (see Suppression Lists). |
Times are ISO 8601 and stored in UTC (2026-11-27T15:04:05.000Z). Days in reports are UTC days.
Errors and Limits
Every error is JSON with an error message, and some carry extra fields:
{ "error": "Lead merged", "mergedInto": "01KD4M9X0E6V7T3W2Q8N5R1B6C" }
| Status | Meaning |
|---|---|
400 |
The request is invalid. The message names the field, never echoes its value. |
401 |
The API key is missing or wrong. |
403 |
The key is read-only and the request writes. |
404 |
The lead, entry or schema does not exist. |
409 |
A conflict: the ID is taken, the address is suppressed, the lead is being merged, or an Idempotency-Key is reused or still in progress. |
500 |
Our fault. Retry with backoff. |
| Limit | Value |
|---|---|
| Lead record (stage, due time and metadata) | 350 KB |
| Metadata keys changed in one write | 100 |
| Server events per request | 25, all or nothing |
| Page size on every list | 100, with a nextCursor; ask for fewer with limit (1 to 100) |
| Search results | 100 a page, 500 in all |
| Text trail entry, email body | 5 MB |
| Trail entry metadata | 4 KB |
| Document upload | 4 MiB |
| Activity feed window | 31 days |
| Stats range | 400 days |
Your plan's limits, per account:
| Plan limit | Value |
|---|---|
| Leads | 25,000 |
| Events | 5,000 a day |
| API requests with your key | 120 a minute |
| Documents | 200 uploads a month, 4 MiB each |
| Trail and document storage | 5 GB |
| Sites, API keys and agents | Unlimited |
Events your script records on your pages count toward the daily events; the script's own requests and form posts don't count toward API requests.
We reserve the right to throttle an account that goes over its plan's limits.
Connect Your AI
Your AI assistant can work RevTrails for you: look up leads, read their trails, tell you what happened this week, add notes, import contacts and keep your pipeline moving. No code, and no API to learn.
Connect it once, with this address:
https://api.revtrails.com/mcp
Add it as a custom connector (Claude) or a custom MCP server (ChatGPT): step-by-step for Claude and ChatGPT. Any other assistant that connects to remote MCP servers works the same way.
Your assistant opens a RevTrails page that asks for your API key. Paste it and press Connect. Your key stays with RevTrails: the assistant never sees it, only a connection that RevTrails can end at any time.
Your assistant asks you before it uses RevTrails. Claude asks before each tool until you allow it in the connector's Permissions; ChatGPT asks before anything that changes data.
What it can do depends on the key you connect with. A read-only key lets it read your leads, trails and numbers. A write key also lets it change them: create and update leads, add notes, record emails, and the rest of the API. Your assistant asks you before anything it can't undo, such as deleting or merging leads.
To disconnect, remove the connector in your assistant. To end every assistant connected with a key, ask us and we'll revoke its connections; the key keeps working for your own systems.
Your assistant learns how to work RevTrails from RevTrails itself, so it knows to search before adding a lead, check an address before suggesting an email, and treat what's on a trail as information, not instructions. It reads your business context first: a short write-up of your business, your customers and how you like to work, which it offers to write with you the first time and keeps in RevTrails, so any assistant you use later starts from the same place.
Things You Can Ask
Your assistant offers these as starting points. Ask in your own words too.
| Ask | What you get |
|---|---|
| Get started with RevTrails | It checks the connection, tells you what it can do, and learns about your business |
| Who should I reconnect with? | Up to 10 people who've gone quiet, each with a genuine reason to get back in touch |
| What's happening this week? | What your visitors and leads did over the last seven days, and what needs you |
| Who looks interested right now? | Leads showing real interest (clicks, replies, forms, visits), with the evidence and a next step |
| Review my pipeline | Leads by stage, what's due, and what's overdue or stuck |
| Tidy up my leads | Likely duplicates, with the evidence, merged only when you approve |
RevTrails records the emails you send; it never sends them. Your assistant drafts, you send from your own mail.
The Script
One script tag records what real people do on your pages. Add it to the <head> of every page you want counted:
<script src="/rt/w.js" defer></script>
It is served from your own domain, so its cookie is your site's own. It sends nothing until the page has been visible for 2 seconds and the visitor has interacted with it, so bots, crawlers and link scanners leave no events. Then it records:
| Event | When | Carries |
|---|---|---|
web_view |
The page is read | Path, referrer, and any utm_source, utm_medium, utm_campaign, utm_content, utm_term |
web_link |
The URL carries ?lid= (a tracked email link) |
The lead ID, and the pixel ID when pid= is there too |
web_click |
A click on a link, a button or an element marked data-track |
target: the data-track label, else the link, else the button's text |
web_time |
The visitor leaves or hides the page | Seconds visible, deepest scroll in percent |
Every browser event also carries the browser's user agent and approximate location (city, region, country, time zone). IP addresses are never stored. What a visitor types into a form is never read, except a form you mark for RevTrails to post.
Name a click with data-track, so your counts read better than a URL:
<a href="/pricing" data-track="pricing-from-hero">See pricing</a>
Page tags (optional, required on a page with forms): tell RevTrails which page this is, so events and forms can be counted by page.
<meta name="data-rt-node-id" content="01KD4M9X0E6V7T3W2Q8N5R1B6C"> <meta name="data-rt-node-version" content="1.2.0">
data-rt-node-id is a ULID you choose for the page; data-rt-node-version is the page's content version.
Purchases
When a purchase is complete, tell RevTrails from the page. Add the one-line stub to the page, then call the hook with the amount, the plan and how it is billed:
<script>window.revtrails=window.revtrails||function(){(revtrails.q=revtrails.q||[]).push(arguments)}</script>
<script>revtrails('purchase', { amount: 49, plan: 'Pro', billing: 'monthly', orderId: 'A-1001' })</script>
| Field | ||
|---|---|---|
amount |
required | A number: what the plan costs per billing period |
plan |
required | The plan's name, as you want it in your numbers |
billing |
required | monthly or annual |
orderId |
optional | Your order ID; a repeat of one already recorded is ignored, so a reloaded confirmation page counts once |
Call it wherever your checkout finishes: on a confirmation page, or in your code when the payment succeeds. The stub keeps a call made before the script has loaded. The purchase is sent at once, and only these four fields leave the page. It is recorded as web_purchase under the visitor, or the lead once the visitor is known, so it joins their history like every other event. A mistake in a call is shown in the browser console.
Anyone who can open your page can call the hook, the same as an analytics purchase event. If you record purchases from your own server instead (web_purchase through server events), ask us to turn browser purchases off for your account so nothing is counted twice.
Forms
Mark a form and RevTrails posts it, screens out bots, records it on the lead and, if you want, emails the lead and your team. Your page needs no script of its own and keeps its own words.
<meta name="data-rt-node-id" content="01KD4M9X0E6V7T3W2Q8N5R1B6C"> <form data-rt-form="kit-download"> <label>Your work email <input type="email" name="email" required></label> <button type="submit">Email me the kit</button> </form> <p data-rt-thanks="kit-download" hidden>Thanks. Check your inbox.</p>
data-rt-formnames the form: lowercase letters, digits and hyphens, at most 64 characters, unique on its page.data-rt-thankswith the same name is your thank-you, hidden. On submit the form is hidden and the thank-you shown. With no thank-you, the form is cleared.- Every named field is sent. Files are left out.
A submission is accepted only from a visitor who really read a page today or yesterday, at least 3 seconds after the page loaded, with the hidden bot trap left empty, at most 20,000 bytes, and under 5 submissions per visitor and 20 per network address an hour. Anything else is dropped silently; the visitor sees the thank-you either way.
An accepted submission:
- Creates the lead if there is none, with the visitor's ID as the lead ID.
- Puts the fields on the lead's metadata under the form's name (
metadata["kit-download"]), replacing an earlier submission of the same form, and keeps every submission as aformentry on the lead's trail. - Records a
web_formevent. - Sends the form's email and notification, if its definition has them.
Publishing Your Forms
How each form is processed comes from your form schema: one JSON document listing every form on your site. Publishing replaces the previous schema whole. A schema that fails a check is refused, and the one in force stays.
curl -s -X PUT https://api.revtrails.com/v1/forms \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d @forms.json
{
"version": 1,
"site": "https://www.example.com",
"forms": [
{
"nodeId": "01KD4M9X0E6V7T3W2Q8N5R1B6C",
"formKey": "kit-download",
"fields": [
{ "name": "email", "type": "email", "required": true, "label": "Your work email" }
],
"leadEmail": "email",
"email": {
"from": { "name": "Dana at Example", "address": "dana@example.com" },
"subject": "Your kit",
"html": "<!DOCTYPE html><html><body><p>Here is your kit…</p></body></html>",
"text": "Here is your kit…"
},
"notify": {
"from": { "name": "Example Forms", "address": "forms@example.com" },
"to": "team@example.com",
"subject": "Kit download"
}
}
]
}
| Key | Rules |
|---|---|
site |
Your site's origin, https:// and a host. Your tracking images are served from it. |
nodeId, formKey |
The page's data-rt-node-id and the form's data-rt-form name. Together they are unique. |
fields |
Up to 50: name (a letter, then letters, digits, _ or -; not hp), type (email, text or textarea), required, label (up to 200 characters). |
leadEmail |
Optional: the email field that holds the lead's address. A form that emails the lead must name it and require it. |
email |
Optional: the email to the lead, from, subject, html and text. |
notify |
Optional: a plain-text notification to your team, from, to and subject. |
The whole schema is at most 1 MB and 2,000 forms. Read the schema in force with GET /v1/forms.
Publish your schema even if you have no forms ("forms": []): its site is where your tracking images are served from, and creating a pixel needs it.
Form Emails and Notifications
A form with an email sends it to the address in its leadEmail field, through your own SendGrid account, from your own domain, with a tracking image added before </body>. The send is recorded on the lead like any other email, so its opens show in the lead's events and in your stats.
A form with a notify sends your team a plain-text message: the page, each filled field under its label, the form's name, the lead ID and the time.
Each email gets three attempts. If something goes wrong (the form isn't in your schema, a field fails its check, the email can't be sent), your account's owner gets an alert naming the form, the reason and the lead ID, at most once per form and reason a day. The submission is always kept on the lead first, so a failure never loses it.
Leads
Create a lead. Send your own ULID as leadId, or leave it out and one is made. Answers 201 { lead }, or 409 when the ID is taken.
curl -s -X POST https://api.revtrails.com/v1/leads \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "stage": "new", "dueAt": "2026-11-28T15:00:00.000Z", "metadata": { "email": "jane@acme.com", "name": "Jane Doe", "company": { "name": "Acme", "size": 120 } } }'
{
"lead": {
"leadId": "01KD4N2H7S8Y0F5A3M6P9C1E4G",
"stage": "new",
"dueAt": "2026-11-28T15:00:00.000Z",
"metadata": { "email": "jane@acme.com", "name": "Jane Doe", "company": { "name": "Acme", "size": 120 } },
"createdAt": "2026-11-27T15:04:05.123Z",
"updatedAt": "2026-11-27T15:04:05.123Z"
}
}
Create many at once: POST /v1/leads/batch with { "leads": [ … ] }, up to 250 leads, each what a single create takes. A bad batch is refused whole with 400 Lead <index>: <reason> and nothing is written. Otherwise every lead is created and reported: 200 { created, conflicts, failed }, each a list of { index, leadId }. A taken leadId is a conflict; nothing is matched on email or any other field. Resend only what comes back in failed, and send an Idempotency-Key header to make a retry of the whole batch safe.
Read a lead: GET /v1/leads/{leadId}. A lead merged into another answers 404 { "error": "Lead merged", "mergedInto": "…" }.
Update a lead. PATCH changes only what it names, so several systems can write to one lead without overwriting each other:
stage: a new code (lowercase letters, digits and hyphens), ornullto clear it.dueAt: when the lead is next due for work, ornullto take it off the work queue.assignedTo: who works the lead, any text up to 256 characters (RevTrails never interprets it), ornullto unassign.metadata: key by key at the top level. A key set tonullis removed; any other key is replaced whole.
curl -s -X PATCH https://api.revtrails.com/v1/leads/LEAD_ID \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "stage": "contacted", "dueAt": "2026-12-05T15:00:00.000Z", "metadata": { "lastTopic": "pricing" } }'
Every stage change records a crm_stage event with the previous stage, every due change a crm_due event and every assignment a crm_assigned event, in the same write. Writing a value equal to the one stored changes nothing.
Delete a lead: DELETE /v1/leads/{leadId} removes the lead, its whole trail and every document. The IDs of leads merged into it stop pointing to it and answer 404 No such lead. Its events stay, and a crm_deleteLead event is recorded. RevTrails never puts a name, an email address or anything a person typed into a form in an event: events hold IDs, the page, the browser and an approximate location. Once a lead is deleted, what remains no longer identifies the person. An address on a suppression list stays on it, so an unsubscribe is still honored.
The Work Queue
dueAt turns your leads into a work queue. Ask for the leads due now, soonest first:
curl -s "https://api.revtrails.com/v1/leads/due" -H "x-api-key: YOUR_API_KEY"
{ "leads": [ { "leadId": "01KD4N2H7S8Y0F5A3M6P9C1E4G", "stage": "contacted", "dueAt": "2026-11-27T15:00:00.000Z", "metadata": { } } ], "nextCursor": null }
before asks for the leads due by a later time; assignedTo only the leads assigned to that value (ignoring case), so each worker reads their own queue; cursor pages on. When your agent finishes with a lead, it sets the next dueAt, or null when nothing more is due.
Merging Leads
When two leads turn out to be one person, merge one into the other. You choose the survivor:
curl -s -X POST https://api.revtrails.com/v1/leads/SURVIVOR_ID/merge \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "from": "MERGED_ID" }'
The merge answers 202 and runs in the background. It is done when GET /v1/leads/MERGED_ID answers 404 { "error": "Lead merged", "mergedInto": "SURVIVOR_ID" }.
- The survivor keeps its own stage, due time and metadata, and gains the metadata keys only the merged lead had.
- It gets the merged lead's whole trail and a copy of its events, plus a
mergeentry holding the merged lead's record. - The merged lead's ID keeps working wherever it went out: its tracking images, email links and browser all record on the survivor.
A 409 says why it can't merge now: Lead already merged, Lead is being merged (try again later), Merged lead too large or Too many metadata keys to merge.
Trail Entries
The trail holds a lead's content. List the headers first, then read only the entries you need:
curl -s "https://api.revtrails.com/v1/leads/LEAD_ID/trail" -H "x-api-key: YOUR_API_KEY" curl -s "https://api.revtrails.com/v1/leads/LEAD_ID/trail/ENTRY_ID" -H "x-api-key: YOUR_API_KEY"
The list is 100 headers a page, oldest first, with from and to to narrow it. An entry's type is email, form, text, document or merge. Reading one entry returns its header and its body, and for a document a download link good for 15 minutes.
| Route | Does |
|---|---|
PATCH /v1/leads/{leadId}/trail/{entryId} |
Changes the entry's metadata, key by key. Nothing else of an entry changes. |
DELETE /v1/leads/{leadId}/trail/{entryId} |
Deletes the entry and its body, a document's file included. |
Notes and Transcripts
Anything written goes on the trail as a text entry: a note, a call transcript, a summary your agent wrote.
curl -s -X POST https://api.revtrails.com/v1/leads/LEAD_ID/trail \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "subject": "Discovery call", "text": "Jane: our hiring managers never agree on what the role needs…", "occurredAt": "2026-11-27T14:30:00.000Z", "metadata": { "kind": "transcript", "durationMinutes": 32 } }'
text is up to 5 MB; metadata is the entry's own tags, up to 4 KB. Answers 201 { entry }.
Documents
Upload a file to a lead in two steps: ask for an upload, then send the file straight to storage.
curl -s -X POST https://api.revtrails.com/v1/leads/LEAD_ID/documents \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "fileName": "proposal.pdf", "contentType": "application/pdf", "fileBytes": 482113 }'
{
"entry": { "entryId": "01KD4P…", "type": "document", "status": "pending" },
"upload": { "url": "https://…", "fields": { "key": "…", "policy": "…" }, "expiresAt": "2026-11-27T15:19:05.000Z" }
}
Send a multipart POST to upload.url with every one of upload.fields, then the file as file, within 15 minutes:
import requests doc = start_upload_response # the JSON above with open("proposal.pdf", "rb") as f: r = requests.post(doc["upload"]["url"], data=doc["upload"]["fields"], files={"file": f}) r.raise_for_status()
When the file lands the entry becomes stored. A file whose text can be read (PDF, Word, RTF, plain text, Excel, PowerPoint, JSON and caption files; scanned images are not read) has its text extracted: the entry becomes extracted, with the text as its body, or failed with an extractionReason. Files are up to 4 MiB. An upload that never arrives is removed after a day.
Sending an Email
You send email from your own mail system. RevTrails tracks it in three steps:
1. Create a pixel for this email to this lead, before you write it:
curl -s -X POST https://api.revtrails.com/v1/leads/LEAD_ID/pixels \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "to": "jane@acme.com", "audienceId": "01KD4Q0B2C3D4E5F6G7H8J9K0M", "nodeId": "01KD4M9X0E6V7T3W2Q8N5R1B6C", "templateId": "01KD4Q7R8S9T0V1W2X3Y4Z5A6B", "templateVersion": "1.0.0" }'
{ "pixelId": "01KD4R3N…", "pixelUrl": "https://www.example.com/rt/tp-01KD4N2H…-01KD4R3N….png" }
to is required and is checked against your suppression lists first: a suppressed address answers 409 Address is suppressed: <lists>, and you don't send. With a nodeId the email is a campaign email; without one it is an answer to the lead. templateId and templateVersion go together, and the send and everything that answers it count for that template version in your stats.
2. Write the email with the pixel before </body>, and add lid and pid to the links to your site:
<a href="https://www.example.com/pricing?lid=LEAD_ID&pid=PIXEL_ID">See pricing</a> … <img src="PIXEL_URL" width="1" height="1" alt=""> </body>
3. Send it, then record it with the email hook:
curl -s -X POST https://api.revtrails.com/v1/leads/LEAD_ID/emails \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "direction": "out", "messageId": "<CAH7x…@mail.example.com>", "from": "dana@example.com", "to": ["jane@acme.com"], "subject": "The hire nobody agreed on", "text": "Hi Jane, …", "html": "<html>…<img src=\"PIXEL_URL\" …></body></html>", "nodeId": "01KD4M9X0E6V7T3W2Q8N5R1B6C", "nodeVersion": "1.2.0", "pixelId": "PIXEL_ID" }'
This records an email_send event and keeps the full email on the lead's trail, together or not at all. Answers 201 { entryId, eventId }.
- The HTML must carry the pixel's URL and no other pixel; an email without a
pixelIdmust carry none. to(andcc) is a list of addresses, even for one recipient. With a pixel, it must be exactly the address the pixel was made for.- Recording the same
pixelIdagain returns the first result and records nothing, so a retry is safe. occurredAtdefaults to now. A send scheduled in your mail system may be recorded up to 48 hours ahead, at the time it will go out.- The body is at most 5 MB.
Recording Replies
Record an email the lead sent you with direction: "in". Name the pixelId of the send it answers when you know it, so the reply counts for that send:
curl -s -X POST https://api.revtrails.com/v1/leads/LEAD_ID/emails \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "direction": "in", "messageId": "<…@acme.com>", "from": "jane@acme.com", "to": ["dana@example.com"], "subject": "Re: The hire nobody agreed on", "text": "This is us. Can we talk Tuesday?", "pixelId": "PIXEL_ID" }'
This records an email_reply event and keeps the reply on the trail. To find which lead wrote, look the sender up by address: GET /v1/leads?value=jane@acme.com (see Searching Leads).
Link Tracking
A link to your site carrying lid=<leadId> joins the visit to that lead: the click is a web_link event, and the browser's earlier anonymous visits join the lead's events. Adding pid=<pixelId> ties the click to that send, so it counts for its template.
https://www.example.com/pricing?lid=01KD4N2H7S8Y0F5A3M6P9C1E4G&pid=01KD4R3N5P6Q7R8S9T0V1W2X3Y
A pid that isn't one of that lead's pixels is ignored; the visit is still kept.
Opens, clicks, replies, bounces and unsubscribes tied to a send carry sendAgeDays. After 60 days they are still recorded but no longer count for the send.
Bounces, Unsubscribes and Complaints
Report what your mail system hears back as server events, with the pixelId of the send when you have it:
curl -s -X POST https://api.revtrails.com/v1/events \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "events": [ { "type": "email_bounce", "leadId": "LEAD_ID", "messageId": "<CAH7x…@mail.example.com>", "bounceType": "hard", "pixelId": "PIXEL_ID" }, { "type": "email_unsubscribe", "leadId": "OTHER_LEAD_ID", "pixelId": "OTHER_PIXEL_ID" } ] }'
When the pixel was made for an address, the address goes on a suppression list before the event is written: an unsubscribe on stop, a complaint on spam, a hard bounce on bounce.
Suppression Lists
Three lists keep you from emailing people who shouldn't hear from you:
| List | Holds | Refuses |
|---|---|---|
stop |
Addresses that asked to stop | Campaign emails |
spam |
Addresses that reported spam | Campaign emails and answers |
bounce |
Addresses that bounced permanently | Campaign emails and answers |
A stop or spam entry applies to one audience (audienceId) or to your whole account; a bounce always applies to your whole account. Creating a pixel checks the lists for you. To check an address yourself before sending:
curl -s "https://api.revtrails.com/v1/suppressions/jane%40acme.com?audienceId=AUDIENCE_ID" -H "x-api-key: YOUR_API_KEY"
{ "address": "jane@acme.com", "entries": [ ], "refuses": { "nodeEmail": false, "answer": false } }
| Route | Does |
|---|---|
GET /v1/suppressions/{address}?audienceId= |
Checks one address and changes nothing. |
GET /v1/suppressions?cursor= |
Lists every entry, removed ones included. |
POST /v1/suppressions |
Adds an address by hand: { "address", "list": "stop" \| "spam" \| "bounce", "audienceId"? }. Answers 201, or 200 when it is already there. |
There is no route to take an address off a list, by design. If one was added by mistake, contact us.
Server Events
Record what your systems did with POST /v1/events: up to 25 events a request, all recorded or none. Each event is its type, its fields, and optionally occurredAt (default now; at most a minute ahead).
curl -s -X POST https://api.revtrails.com/v1/events \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "events": [ { "type": "manual_purchase", "leadId": "LEAD_ID", "amount": 799, "term": "new", "billing": "annual", "plan": "Pro", "occurredAt": "2026-11-27T16:00:00.000Z" } ] }'
{ "recordedCount": 1 }
Retry safely with an Idempotency-Key header (any string up to 200 characters, unique to the request). A retry with the same key within 24 hours records nothing and answers what the first request answered. The same key with a different body answers 409 Idempotency key reused, and while the first request is still running, 409 Request in progress. A request that fails frees its key.
curl -s -X POST https://api.revtrails.com/v1/events \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -H "Idempotency-Key: order-A-1001" \ -d '{ "events": [ { "type": "web_purchase", "leadId": "LEAD_ID", "amount": 799, "term": "new", "billing": "annual", "plan": "Pro" } ] }'
A purchase or refund may be recorded with a past occurredAt, and counts on that day. Every purchase carries billing, monthly or annual; a monthly plan's amount is its monthly price. Emails sent and replies are recorded only through the email hook, never here.
Event Types
Every type is named <channel>_<what happened>.
| Type | Recorded by | Fields |
|---|---|---|
web_view |
The script | utmSource, utmMedium, utmCampaign, utmContent, utmTerm |
web_time |
The script | visibleSeconds, scrollPercent |
web_click |
The script | target |
web_link |
The script | leadId, pixelId |
web_form |
A form submission | formName |
web_purchase |
You: a purchase on your site, from your server or the page | From your server: leadId, amount, term (new or renewal), billing (monthly or annual), plan. From the page: amount, plan, billing, orderId |
pixel_fetch |
A tracking image load (an open) | leadId, pixelId, nodeId |
email_send |
The email hook, out |
leadId, messageId, pixelId, nodeId, nodeVersion, templateId, templateVersion |
email_reply |
The email hook, in |
leadId, messageId, pixelId |
email_bounce |
You | leadId, messageId, bounceType (hard or soft), pixelId |
email_unsubscribe |
You | leadId, pixelId |
email_complaint |
You | leadId, messageId, pixelId |
bdr_placement |
You: your agent placed the lead on a page or step | leadId, nodeId |
bdr_move |
You: your agent moved the lead from one to another | leadId, fromNodeId, toNodeId |
manual_purchase |
You: a purchase made elsewhere | leadId, amount, term, billing, plan |
manual_refund |
You | leadId, amount |
crm_stage, crm_due, crm_assigned |
RevTrails, on every change | stage and previousStage; dueAt and previousDueAt; assignedTo and previousAssignedTo |
crm_addTrail, crm_updateTrail, crm_deleteTrail |
RevTrails | entryId, and entryType on add |
crm_deleteLead, crm_mergeLead |
RevTrails | leadId; mergedLeadId |
Browser events (web_*, pixel_fetch) also carry the page's path, referrer and page tags, the session, the user agent and the approximate location.
Reading Events
One lead's events, oldest first, its anonymous visits from before it became a lead included:
curl -s "https://api.revtrails.com/v1/leads/LEAD_ID/events?from=2026-11-01T00:00:00.000Z" -H "x-api-key: YOUR_API_KEY"
Everything that happened across your leads in a window of up to 31 days, oldest first: the way to catch up on what changed since you last looked.
curl -s "https://api.revtrails.com/v1/activity?from=2026-11-27T00:00:00.000Z" -H "x-api-key: YOUR_API_KEY"
{ "activity": [ { "leadId": "01KD4N2H…", "type": "pixel_fetch", "occurredAt": "2026-11-27T09:12:44.512Z", "eventId": "…" } ], "nextCursor": "…" }
Both are 100 a page; pass cursor for the next.
RevTrails doesn't push events to you: there are no webhooks. Read GET /v1/activity?from=<your last run> on your own schedule, and keep the time of each run for the next.
Search Schema
Every lead and every trail entry is searchable. Your search schema names the fields of your lead metadata to match exactly and count by: up to 50, at least one of them an email.
curl -s -X PUT https://api.revtrails.com/v1/search-schema \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "version": 1, "fields": [ { "path": "email", "type": "email" }, { "path": "company.name", "type": "text" }, { "path": "company.size", "type": "number" }, { "path": "firstSeen", "type": "date" } ] }'
path is a dot path into the lead's metadata; an array's values all count. type is text, number, date (ISO), email or boolean (true or false). Publishing replaces the schema and re-indexes your leads in the background ({ "reindex": "started" }). Read it with GET /v1/search-schema.
Searching Leads
GET /v1/leads searches; it needs at least one of value, field or q.
| Parameter | Finds |
|---|---|
value |
Leads holding that value, whole and ignoring case, in any schema field. An address is read as an address: Jane <Jane@Acme.com> is jane@acme.com. |
field |
With value, one schema field (true or false for a boolean field); with from and to, a range on a number or date field: dates in ISO form (2026-11-30 or 2026-11-30T14:00:00Z), and a to that is a date alone takes in that whole day (UTC). |
q |
Free text over everything on the lead: every word must appear, word forms match ("priced" finds "pricing"), and an address splits into its parts, so q=acme.com finds jane@acme.com. |
stage |
Only leads at that stage. |
assignedTo |
Only leads assigned to that value, ignoring case. |
in |
Also search trail entries: any of emails, forms, notes, documents, merges. With in=emails, value also matches an email's from, to and cc. |
# Who wrote to us? curl -s "https://api.revtrails.com/v1/leads?value=jane@acme.com&in=emails" -H "x-api-key: YOUR_API_KEY" # Leads at mid-size companies that mentioned pricing in any email or note curl -s "https://api.revtrails.com/v1/leads?field=company.size&from=50&to=500" -H "x-api-key: YOUR_API_KEY" curl -s "https://api.revtrails.com/v1/leads?q=pricing&in=emails,notes" -H "x-api-key: YOUR_API_KEY"
{ "leads": [ { "leadId": "01KD4N2H…", "stage": "contacted", "metadata": { }, "matched": ["01KD4P…"] } ], "total": 1, "totalExact": false, "nextCursor": null }
Each lead comes back whole, plus matched: the trail entries that matched. stage, assignedTo and field search lead records only, so any of them with in is refused. total is exact without in, approximate with it. A lead written a moment ago may take a few seconds to be found.
Counting Leads
Count your leads by stage, by assignedTo, or by any schema field, over all of them or over a search:
curl -s "https://api.revtrails.com/v1/reports/lead-counts?by=stage" -H "x-api-key: YOUR_API_KEY"
{ "by": "stage", "counts": [ { "value": "qualified", "leads": 1950 }, { "value": "contacted", "leads": 100 } ], "more": false, "none": 2, "total": 2052 }
It takes the same filters as a search, without in. At most 100 groups come back (more is true when there are others); none counts the leads with no stage (by stage) or no assignee (by assignedTo).
Stats by Period
Your numbers by day, week (starting Monday), month, quarter or year, in UTC. start is a period's first day; end (optional) is any day up to 400 days later.
curl -s "https://api.revtrails.com/v1/stats/period?period=month&start=2026-09-01&end=2026-11-30" -H "x-api-key: YOUR_API_KEY"
{
"period": "month",
"periods": [
{
"start": "2026-11-01",
"events": { "web_view": 4210, "web_form": 37 },
"sessions": 2980,
"visitors": { "new": 2210, "returning": 340, "leads": 412 },
"emails": { "sent": 1200, "delivered": 1171, "opened": 503, "clicked": 88 },
"revenue": { "newSubscribers": 3, "newArr": 2397, "renewals": 0, "renewalArr": 0, "refunded": 0, "arr": 2397 }
}
]
}
visitors: distinct visitors;returningis all of them less the new;leadsthe known leads among them.emails: campaign and form emails sent in the period.deliveredis sent less bounced;openedandclickedcount first events within 60 days of the send, so a closed period can still rise.revenue: a new purchase adds its yearly revenue: the amount for an annual plan, twelve times the amount for a monthly one; a renewal adds its amount;arris purchases less refunds over the 12 months ending on the period's last day. Later monthly charges and cancellations are yours to record.
Email Template Stats
How each email template performs, by the day it was sent:
curl -s "https://api.revtrails.com/v1/stats/templates/TEMPLATE_ID?from=2026-11-01&to=2026-11-30" -H "x-api-key: YOUR_API_KEY"
{ "templateId": "01KD4Q7R…", "days": [ { "date": "2026-11-24", "templateVersion": "1.0.0",
"counts": { "sent": 100, "bounced": 2, "delivered": 98, "opened": 41, "clicked": 9, "replied": 3, "unsubscribed": 1 } } ] }
Counts are cohorts of each day's sends; opened, clicked, replied and unsubscribed count first events within 60 days. Sum rows for weeks or months, and work rates out from the summed counts. GET /v1/stats/templates?date=2026-11-24 lists every template sent that day.
The Agent Loop
RevTrails is built to be an agent's memory of every lead: what happened, what was said, and when to act next. A working loop is five calls:
- Pick up work:
GET /v1/leads/duereturns the leads due now. - Read the lead:
GET /v1/leads/{leadId},GET /v1/leads/{leadId}/eventsand the trail headers, then only the entries worth reading. - Decide what this lead should see next. That part is yours.
- Act and record: create a pixel, send through your mail system, record the send with the email hook. Write a note with your reasoning if you want it kept.
- Schedule the next touch:
PATCHthe lead'sstageanddueAt.
import os, smtplib, requests from dataclasses import dataclass from datetime import datetime, timedelta, timezone from email.message import EmailMessage from email.utils import make_msgid API = "https://api.revtrails.com" H = {"x-api-key": os.environ["REVTRAILS_KEY"], "Content-Type": "application/json"} def rt(method, path, **kw): r = requests.request(method, API + path, headers=H, timeout=30, **kw) r.raise_for_status() return r.json() if r.content else None @dataclass class Plan: stage: str wait_days: int reasoning: str email: bool = False to: str = "" sender: str = "" subject: str = "" text: str = "" html: str = "" node_id: str = "" def decide(lead, events, trail): """Your agent goes here: read the lead, its events and its trail, and decide what it sees next. This placeholder sends nothing and looks again in 3 days.""" return Plan(stage=lead.get("stage") or "new", wait_days=3, reasoning=f"{len(events)} events, {len(trail)} trail entries: nothing to send yet.") def send_email(to, sender, subject, text, html): """Sends through your own SMTP server and returns the message's ID.""" msg = EmailMessage() msg["From"], msg["To"], msg["Subject"] = sender, to, subject msg["Message-ID"] = make_msgid() msg.set_content(text) msg.add_alternative(html, subtype="html") with smtplib.SMTP(os.environ["SMTP_HOST"], 587) as smtp: smtp.starttls() smtp.login(os.environ["SMTP_USER"], os.environ["SMTP_PASSWORD"]) smtp.send_message(msg) return msg["Message-ID"] for lead in rt("GET", "/v1/leads/due")["leads"]: lid = lead["leadId"] events = rt("GET", f"/v1/leads/{lid}/events")["events"] trail = rt("GET", f"/v1/leads/{lid}/trail")["entries"] plan = decide(lead, events, trail) if plan.email: px = rt("POST", f"/v1/leads/{lid}/pixels", json={"to": plan.to, "nodeId": plan.node_id}) html = plan.html.replace("</body>", f'<img src="{px["pixelUrl"]}" width="1" height="1" alt=""></body>') message_id = send_email(plan.to, plan.sender, plan.subject, plan.text, html) rt("POST", f"/v1/leads/{lid}/emails", json={ "direction": "out", "messageId": message_id, "from": plan.sender, "to": [plan.to], "subject": plan.subject, "text": plan.text, "html": html, "nodeId": plan.node_id, "pixelId": px["pixelId"]}) rt("POST", f"/v1/leads/{lid}/trail", json={"subject": "Agent note", "text": plan.reasoning}) next_due = datetime.now(timezone.utc) + timedelta(days=plan.wait_days) rt("PATCH", f"/v1/leads/{lid}", json={"stage": plan.stage, "dueAt": next_due.isoformat(timespec="milliseconds").replace("+00:00", "Z")})
The script runs as it stands. decide is the one part that is yours: replace the placeholder with your agent, and send_email with your mail system if it isn't SMTP.
To catch what happened between runs (an open, a click, a form, a reply), read GET /v1/activity?from=<last run> and move a lead's dueAt to now when something it did should change what it sees next.
Inbound: Replies and Forms
When an email arrives, find who sent it, keep it on their trail, and wake the lead:
const API = 'https://api.revtrails.com' const headers = { 'x-api-key': process.env.REVTRAILS_KEY, 'Content-Type': 'application/json' } async function onInboundEmail(msg) { const found = await fetch(`${API}/v1/leads?value=${encodeURIComponent(msg.from)}&in=emails`, { headers }).then((r) => r.json()) const lead = found.leads[0] if (!lead) { console.log(`No lead for ${msg.from}: decide whether this sender becomes one`) // or create the lead here return } await fetch(`${API}/v1/leads/${lead.leadId}/emails`, { method: 'POST', headers, body: JSON.stringify({ direction: 'in', messageId: msg.messageId, from: msg.from, to: [].concat(msg.to), subject: msg.subject, text: msg.text, html: msg.html }), }) await fetch(`${API}/v1/leads/${lead.leadId}`, { method: 'PATCH', headers, body: JSON.stringify({ dueAt: new Date().toISOString() }), // due now: answer it }) }
Form submissions need no code: RevTrails puts them on the lead and records web_form. Your agent sees them in the activity feed, in the lead's events, and as form entries on the trail.
Tool Definitions
Give your agent RevTrails as tools. These definitions use JSON Schema, which works with any agent framework or model API that takes function definitions; map each tool to the route in its description.
[
{
"name": "find_leads",
"description": "Search leads. GET /v1/leads. Use value for an exact email or field value, q for free text, in to also search emails, forms, notes or documents.",
"input_schema": {
"type": "object",
"properties": {
"value": { "type": "string" },
"q": { "type": "string" },
"stage": { "type": "string" },
"in": { "type": "string", "description": "Comma list of emails, forms, notes, documents, merges" }
}
}
},
{
"name": "get_due_leads",
"description": "Leads due for work now, soonest first. GET /v1/leads/due.",
"input_schema": { "type": "object", "properties": { "before": { "type": "string", "format": "date-time" } } }
},
{
"name": "read_lead",
"description": "A lead's record and its events, oldest first. GET /v1/leads/{leadId} and GET /v1/leads/{leadId}/events.",
"input_schema": { "type": "object", "properties": { "leadId": { "type": "string" } }, "required": ["leadId"] }
},
{
"name": "read_trail",
"description": "List a lead's trail entry headers, or read one entry in full when entryId is given. GET /v1/leads/{leadId}/trail[/{entryId}].",
"input_schema": { "type": "object", "properties": { "leadId": { "type": "string" }, "entryId": { "type": "string" } }, "required": ["leadId"] }
},
{
"name": "update_lead",
"description": "Set a lead's stage, next due time, assignee and metadata keys. PATCH /v1/leads/{leadId}. Only what is named changes; null clears.",
"input_schema": {
"type": "object",
"properties": {
"leadId": { "type": "string" },
"stage": { "type": ["string", "null"] },
"dueAt": { "type": ["string", "null"], "format": "date-time" },
"assignedTo": { "type": ["string", "null"] },
"metadata": { "type": "object" }
},
"required": ["leadId"]
}
},
{
"name": "add_note",
"description": "Keep a note or transcript on a lead's trail. POST /v1/leads/{leadId}/trail.",
"input_schema": {
"type": "object",
"properties": { "leadId": { "type": "string" }, "subject": { "type": "string" }, "text": { "type": "string" } },
"required": ["leadId", "text"]
}
},
{
"name": "check_address",
"description": "Whether an address may be emailed. GET /v1/suppressions/{address}.",
"input_schema": { "type": "object", "properties": { "address": { "type": "string" } }, "required": ["address"] }
}
]
Keep sending in your own code rather than as a tool: create the pixel, send, and record the send in one function, so a send is never left unrecorded.
This page is also served as plain text at /llms.txt, so your agent can read the whole API in one fetch.
All Routes
All /v1/* routes are at https://api.revtrails.com and take your API key.
| Route | Does |
|---|---|
POST /v1/leads |
Create a lead |
POST /v1/leads/batch |
Create up to 250 leads |
GET /v1/leads?value=&field=&from=&to=&q=&stage=&in=&cursor= |
Search leads |
GET /v1/leads/due?before=&assignedTo=&cursor= |
The leads due for work |
GET /v1/leads/{leadId} |
Read a lead |
PATCH /v1/leads/{leadId} |
Change a lead's stage, due time or metadata |
DELETE /v1/leads/{leadId} |
Delete a lead and its trail |
POST /v1/leads/{leadId}/merge |
Merge another lead into this one |
GET /v1/leads/{leadId}/events?from=&to=&cursor= |
A lead's events |
GET /v1/leads/{leadId}/trail?from=&to=&cursor= |
A lead's trail entry headers |
POST /v1/leads/{leadId}/trail |
Add a note or transcript |
POST /v1/leads/{leadId}/documents |
Start a document upload |
GET /v1/leads/{leadId}/trail/{entryId} |
Read one trail entry |
PATCH /v1/leads/{leadId}/trail/{entryId} |
Change an entry's metadata |
DELETE /v1/leads/{leadId}/trail/{entryId} |
Delete an entry |
POST /v1/leads/{leadId}/pixels |
Create a tracking pixel for an email |
POST /v1/leads/{leadId}/emails |
Record an email sent or received |
POST /v1/events |
Record server events |
GET /v1/activity?from=&to=&cursor= |
Everything that happened across your leads |
GET /v1/suppressions/{address}?audienceId= |
Check an address |
GET /v1/suppressions?cursor= |
List suppression entries |
POST /v1/suppressions |
Add an address to a list |
PUT /v1/forms |
Publish your form schema |
GET /v1/forms |
Read your form schema |
PUT /v1/search-schema |
Publish your search schema |
GET /v1/search-schema |
Read your search schema |
GET /v1/reports/lead-counts?by=&… |
Count leads by stage, assignee or field |
GET /v1/stats/period?period=&start=&end= |
Your numbers by period |
GET /v1/stats/templates/{templateId}?from=&to= |
One template's numbers |
GET /v1/stats/templates?date=&cursor= |
Every template sent on a day |
GET /v1/account |
Your account's name, your key's access and your plan's limits |
GET /v1/context |
Your business context, for any assistant or agent to read first |
PUT /v1/context |
Save your business context { text } (Markdown, up to 100 KB) |
Every list route takes an optional limit (1 to 100) for a smaller page.
Served on your own domain by the script, without a key:
| Route | Does |
|---|---|
GET /rt/w.js |
The script |
POST /rt/collect |
Page events from the script |
POST /rt/forms |
Form submissions from the script |
GET /rt/tp-<leadId>-<pixelId>.png |
A tracking image |
Questions, or something you need that isn't here? info@revtrails.com