Facebook Pixel
Campaigns

Authoring a flow

How to build a campaign flow over the API — the step shape, step types and their config, how to order and branch steps with a DAG, the validation rules, and a complete worked example.

A campaign's flow is an ordered sequence of LinkedIn steps that forms a directed graph (a DAG): steps run in order, and a step can branch on the outcome of an earlier one.

You rarely need to write one by hand — create-campaign already attaches a working default flow. Author one only to customize. Read the current flow with get-campaign-flow; set a new one with replace-campaign-flow, which is a full replace of the step list:

connectsafely replace-campaign-flow --id "$CAMP" --steps '<JSON array of steps>'
PUT /v1/campaigns/{id}/flow
Authorization: Bearer <api-key>
Content-Type: application/json

{ "steps": [ … ] }

The MCP tool replace-campaign-flow takes the same steps array.

The step shape

{
  "order": 0,
  "type": "CONNECT",
  "config": { "withNote": false },
  "linkedInAccountId": "<accountId>",
  "dependsOnStepIds": ["<parentOrder>"],
  "edgeConditions": { "<parentOrder>": "<expression>" }
}
FieldRequiredMeaning
orderyesRun position. Number steps 0, 1, 2, …
typeyesA step type (see below)
configyesStep-specific settings (may be {})
linkedInAccountIdyesWhich of your accounts runs the step
dependsOnStepIdsnoParent steps. Omit on a linear step — it auto-links to the previous order
edgeConditionsnoPer-parent condition that must hold for this step to run (branching)

Ordering and branching

Steps sort by order. A linear step leaves out dependsOnStepIds and automatically follows the previous step. To branch, reference parents by their order number as a string ("7") — you do not pre-allocate step ids — and give each branch an edgeConditions expression:

{ "order": 8, "type": "MESSAGE", "config": { "aiFirstMessage": true },
  "linkedInAccountId": "$ACC", "dependsOnStepIds": ["7"],
  "edgeConditions": { "7": "steps.7.result.accepted == true" } }

Gate steps expose a result the branch keys on: WAIT_FOR_ACCEPT → result.accepted, WAIT_FOR_REPLY → result.replied. Give one branch == true and the other == false off the same parent.

Step types and their config

The common steps (the config shapes shown are the real ones the engine stores):

typeconfignotes
PROFILE_VIEW{}Visits the profile (shows in "who viewed you")
DELAY{ "delaySeconds": 10800 }Wait between steps
LIKE_LATEST_POST{}
COMMENT_LATEST_POST{ "aiComment": true } or { "text": "…" }One is required
FOLLOW{}
CONNECT{ "withNote": false } or { "withNote": true, "aiNote": true }The invite
WAIT_FOR_ACCEPT{ "timeoutSeconds": 604800 }Gate; branch on result.accepted
MESSAGE{ "aiFirstMessage": true } or { "text": "…" }One is required; with aiReply:true, text is a fallback
WITHDRAW_INVITATION{}
ENDORSE_SKILL{}

Also available (same step shape): UNFOLLOW, REACT, REPOST, CHECK_RELATIONSHIP, FETCH_PROFILE, FETCH_CONTACT_INFO, LIKE_COMMENT, REPLY_TO_COMMENT, FOLLOW_COMPANY, SEARCH_PEOPLE, SEARCH_POSTS, SCRAPE_POST, MESSAGE_VIA_GROUP, WAIT_FOR_REPLY, CONDITION, BRANCH, CHECK_OPEN_PROFILE, EMAIL_ENRICHMENT, PUSH_TO_CRM, PUSH_TO_INSTANTLY, PUSH_TO_SMARTLEAD, PUSH_TO_LEMLIST, ADD_LABEL. REPLY_TO_COMMENT and MESSAGE_VIA_GROUP require config.text.

Validation rules

A replace-campaign-flow call is rejected (with a per-step error) when:

  • Step 0 is not a LinkedIn action — it may not be CONDITION, BRANCH or DELAY.
  • A MESSAGE has neither aiFirstMessage: true nor a text body; or a COMMENT / COMMENT_LATEST_POST has neither aiComment: true nor text.
  • A token reference ({{firstName}}, steps.N…) points at a step that does not run before it.
  • The campaign is completed (its flow is read-only), or a run is in flight — pause or let it finish first.

Worked example — the proven "two-chance" flow

Warm up, connect, and give a declined invite a second window before withdrawing. This is the flow create-campaign seeds by default; reproduce or adapt it:

[
  { "order": 0, "type": "PROFILE_VIEW", "config": {}, "linkedInAccountId": "$ACC" },
  { "order": 1, "type": "DELAY", "config": { "delaySeconds": 10800 }, "linkedInAccountId": "$ACC" },
  { "order": 2, "type": "LIKE_LATEST_POST", "config": {}, "linkedInAccountId": "$ACC" },
  { "order": 3, "type": "DELAY", "config": { "delaySeconds": 10800 }, "linkedInAccountId": "$ACC" },
  { "order": 4, "type": "COMMENT_LATEST_POST", "config": { "aiComment": true }, "linkedInAccountId": "$ACC" },
  { "order": 5, "type": "DELAY", "config": { "delaySeconds": 7200 }, "linkedInAccountId": "$ACC" },
  { "order": 6, "type": "CONNECT", "config": { "withNote": false }, "linkedInAccountId": "$ACC" },
  { "order": 7, "type": "WAIT_FOR_ACCEPT", "config": { "timeoutSeconds": 604800 }, "linkedInAccountId": "$ACC" },
  { "order": 8, "type": "MESSAGE", "config": { "aiFirstMessage": true, "aiReply": false },
    "linkedInAccountId": "$ACC", "dependsOnStepIds": ["7"],
    "edgeConditions": { "7": "steps.7.result.accepted == true" } },
  { "order": 9, "type": "WITHDRAW_INVITATION", "config": {},
    "linkedInAccountId": "$ACC", "dependsOnStepIds": ["7"],
    "edgeConditions": { "7": "steps.7.result.accepted == false" } }
]

Reads as: view → like → AI-comment → connect → wait 7 days for accept; accepted sends an AI first message, declined withdraws the invite. A minimal flow is just PROFILE_VIEW → CONNECT → WAIT_FOR_ACCEPT → MESSAGE (accepted branch).

On this page