Build an Agent

Enrol a lead, send a touch, leave a draft for a human, and react to replies — the full agent loop in about 15 minutes.

Build an Agent

Sprootal is the execution layer your agent drives. The agent decides who to reach and what to say; Sprootal owns the LinkedIn account, the pacing, and the Inbox where a human stays in the loop.

This page walks the whole loop end to end. Budget about 15 minutes.

enrol a lead  →  it gets touched  →  they reply  →  your agent drafts  →  a human approves
     REST            campaign          webhook          REST / MCP            Inbox
Everything below uses the REST API. If your agent is an LLM client — Claude, Cursor, n8n — you can drive the same loop over MCP instead; see [the MCP guide](https://sprootal.com/docs) and [Guide: Claude + MCP](/help/guide-claude).

1. Create the lead

A contact needs a home — pass a projectId or a listId:

curl -s -X POST "$SPROOTAL/contacts" \
  -H "Authorization: Bearer $SPROOTAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "firstName": "Jane",
    "lastName": "Doe",
    "linkedin": "https://www.linkedin.com/in/janedoe/",
    "projectId": "'"$PROJECT_ID"'"
  }'

The response carries the id you use everywhere else. Calling this again with the same LinkedIn identity updates that contact instead of creating a duplicate — and brings it back if it had been deleted — so a retried or re-run request is always safe. Pass companyId (from create_company) to set the contact's current company at the same time.


2. Enrol them into a campaign

Enrol into a campaign that already exists:

curl -s "$SPROOTAL/automations" -H "Authorization: Bearer $SPROOTAL_KEY"

curl -s -X POST "$SPROOTAL/automations/$AUTOMATION_ID/enroll" \
  -H "Authorization: Bearer $SPROOTAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "contactIds": ["'"$CONTACT_ID"'"] }'

From here Sprootal runs the sequence on its own schedule: working hours, daily limits, and a minimum gap between actions on the same sender account. Your agent does not need to pace anything — and cannot rush it.

Or build the campaign yourself

A campaign can also be created from a linear chain of blocks:

curl -s -X POST "$SPROOTAL/automations"   -H "Authorization: Bearer $SPROOTAL_KEY"   -H "Content-Type: application/json"   -d '{
    "name": "Founder outreach",
    "project_id": "'"$PROJECT_ID"'",
    "blocks": [
      { "type": "send_connection", "message": "Hi {{firstName}} — saw your post on onboarding." },
      { "type": "wait", "value": 2, "unit": "day" },
      { "type": "send_message", "message": "Worth a short call this week?" }
    ]
  }'

It is created as a draft. Creating a campaign never starts it — activate it deliberately once a human has read it:

curl -s -X PUT "$SPROOTAL/automations/$AUTOMATION_ID/status"   -H "Authorization: Bearer $SPROOTAL_KEY"   -H "Content-Type: application/json"   -d '{ "status": "active" }'

Blocks: send_connection · send_message · send_inmail · visit_profile · like_post · wait · add_tag · remove_tag · change_stage.

Set which sender accounts run it with PUT /automations/{id}/senders — { "sender_ids": [...] } replaces the list. A sender can't be dropped while it still has contacts mid-sequence in that campaign; remove it in the app instead, which asks what to do with those contacts.

Read a campaign back the same way — GET /automations/{id} returns structure.blocks. A campaign built in the app with branches returns structure.linear: false and blocks: null rather than the part of it that happens to be a straight line.

Schema v1 is a linear chain, so branching blocks — conditions, A/B splits, wait-for-reply, connection checks — are rejected with a message telling you so. A list cannot say where each outcome goes, and guessing a default would build a campaign that behaves differently from the one you wrote. Build those in the app and enrol into them over the API.


3. Hear about the reply

Poll nothing. Subscribe once:

curl -s -X POST "$SPROOTAL/webhooks" \
  -H "Authorization: Bearer $SPROOTAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "agent",
    "url": "https://your-agent.example.com/sprootal",
    "events": ["conversation.new_message", "draft.superseded"]
  }'

The response contains signingSecret once — store it. Every delivery carries three headers: X-LeadGen-Signature (t=<unix_ts>,v1=<hex HMAC-SHA256> of {timestamp}.{raw body}), X-LeadGen-Event, and X-LeadGen-Delivery (a unique id, handy for dedup). Recompute the HMAC with your signingSecret and reject anything older than five minutes.

Fire a test delivery through the real dispatch path (same signature, same retry policy) before you trust it:

curl -s -X POST "$SPROOTAL/webhooks/$WEBHOOK_ID/test" \
  -H "Authorization: Bearer $SPROOTAL_KEY"

Deliveries retry 5 times with exponential backoff; every attempt is visible under /webhooks/deliveries. An endpoint that fails 20 times running gets switched off automatically and fires webhook.disabled — to your other endpoints, since the one that died can't announce it. If this is your only endpoint, check /webhooks/deliveries yourself once in a while.

Events worth subscribing to

EventFires when
conversation.new_messageA contact replies — this is your agent's cue
message.sentAnything went out from one of your accounts
lead.campaign_completedA contact reached the end of a campaign — time to hand off or follow up
draft.createdA draft is waiting for review (yours or the platform's)
draft.approvedA human approved and it was sent
draft.discardedA human rejected it — useful training signal
draft.supersededYour pending draft will never be reviewed (see below)

Deal events (deal.created, deal.won, deal.lost, …) and lead.created/lead.updated exist on the same system if your agent also tracks pipeline.


4. Draft a reply

This is the important step. Your agent does not send — it proposes.

The conversation.new_message payload carries data.contact.id and data.senderProfile.id — those are the ids you need:

curl -s -X POST "$SPROOTAL/contacts/$CONTACT_ID/drafts" \
  -H "Authorization: Bearer $SPROOTAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender_id": "'"$SENDER_ID"'",
    "text": "Happy to walk you through pricing — are you free Thursday?",
    "agentName": "clay-followup",
    "playbookLabel": "pricing",
    "confidence": 0.82
  }'

The draft appears on the conversation in the Inbox with your agent's name and confidence on it. A human reads it and clicks Approve and send, edits it first, regenerates it against the template named in playbookLabel, or discards it.

sender_id matters because one contact can have threads with more than one of your LinkedIn accounts. List what's waiting with GET /contacts/{id}/drafts?sender_id=..., and discard one with DELETE /drafts/{draftId}.

Your draft can expire

If the conversation moves on before anyone reviews it — someone else replies, the contact writes again — the draft is swept to obsolete and will never be seen. You get draft.superseded with a reason. Handle it: that is your signal to draft again against the new state, not to retry the old text.


5. Send without a human — the escape hatch

Three ways to put a message on the wire without anyone clicking Approve, all gated the same way:

  • POST /contacts/{id}/drafts with "autoSend": true instead of leaving it pending
  • POST /drafts/{draftId}/approve — send a draft someone else already left
  • POST /contacts/{id}/messages — skip the draft entirely: { "sender_id": "...", "text": "..." }
All three require an **owner- or admin-created** API key. A key from any other role gets `403 FORBIDDEN`: "Sending requires an API key created by a workspace owner or admin. Create a draft instead and have a human approve it." This is a deliberate choice about who can decide a human isn't needed — not a plan or scope limit.

None of these send instantly. Each one is accepted (202) and enqueued onto the same paced schedule the campaign scheduler uses — one action at a time per sender, inside working hours, under the daily cap. The response tells you where it landed:

{
  "data": {
    "id": "...",
    "status": "queued",
    "position": 3,
    "estimated_send_at": "2026-11-26T14:32:00Z"
  }
}

Track it with GET /messages/queue/{id} (or list with /messages/queue); cancel or edit the text with DELETE / PATCH on the same id while it's still waiting. There's nothing to retry — a message you send twice because you weren't sure the first one landed is a duplicate the recipient sees, not a safety net.

Retrying because a send feels slow does not get it out faster. The pacing exists because LinkedIn restricts accounts that behave like software, and a restricted account costs your customer more than a late reply.

6. Same loop from an LLM client

If your agent is Claude, Cursor or an n8n AI Agent, connect over MCP and skip the HTTP plumbing entirely:

search_messages / get_message  → read the conversation
create_draft                   → leave the reply

MCP also exposes send_message, send_connection_request, visit_profile and like_post directly — gated by the same owner-or-admin check as the REST escape hatch above, so an ungated key can't send from a chat either. There is still no tool that approves someone else's draft over MCP: that action stays on REST, on purpose, because an MCP client is the model itself, and letting it approve its own draft would remove the human the loop is built around.

Setup for each client: Guide: Claude + MCP, or sprootal.com/docs for the full tool and scope list.


Where to go next

Tool-specific walkthroughs of this same loop:

Reference: