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>" }
}| Field | Required | Meaning |
|---|---|---|
order | yes | Run position. Number steps 0, 1, 2, … |
type | yes | A step type (see below) |
config | yes | Step-specific settings (may be {}) |
linkedInAccountId | yes | Which of your accounts runs the step |
dependsOnStepIds | no | Parent steps. Omit on a linear step — it auto-links to the previous order |
edgeConditions | no | Per-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):
| type | config | notes |
|---|---|---|
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,BRANCHorDELAY. - A
MESSAGEhas neitheraiFirstMessage: truenor atextbody; or aCOMMENT/COMMENT_LATEST_POSThas neitheraiComment: truenortext. - 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).
Campaigns
Create, fill and run multi-step LinkedIn outreach campaigns over the ConnectSafely API, CLI and MCP server. Every campaign is created in DRAFT with a ready default flow — nothing sends until you start it.
Getting started
Install the ConnectSafely CLI and run your own LinkedIn account from a terminal, a CI job or an AI agent — no server to host, no protocol to speak.
