Preskočiť na obsah
API dokumentácia

Recept: návrat neaktívnych zákazníkov (win-back)

Cieľ: zákazník, ktorý nenakúpil 120 dní, dostane pripomenutie; keď do týždňa nenakúpi, druhý e-mail s výhodou. Každý zákazník prejde sériou len raz.

Graf

Graf
[kazdy-den] trigger_repeat every 1 day, filter: posledná objednávka staršia než 120 dní A aspoň 1 objednávka, reentry once
  → [email-1] send_email → [tyden] wait 7 days
  → [nakoupil] condition ordered_since_entry
       ├─ yes → koniec
       └─ no  → [email-2] send_email
[cil] goal: ordered_since_entry  (kto nakúpi, opúšťa scenár kdekoľvek)
  • trigger_repeat prejde každý deň (od startAt) kontakty e-shopu, ktoré splnia filter. Filter je strom pravidiel segmentu a podmienok, ktoré nepotrebujú beh.
  • reentry: "once": kontakt vstúpi raz a navždy, aj keď filter spĺňa každý deň.
  • Uzol goal nemá hrany; pred každým krokom sa kontroluje, a kto cieľ splní, scenár opúšťa.

1. Šablóny

Požiadavka: POST /api/v1/tenants/{tenant}/templates
curl -sS -X POST "https://www.postarna.cz/api/v1/tenants/$TENANT/templates" \
  -H "Authorization: Bearer $POSTARNA_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "name": "Win-back 1",
  "subject": "Chybíte nám",
  "preheader": "Podívejte se, co je u nás nového",
  "content": {
    "editor": "html",
    "design": null,
    "html": "<!doctype html><html><body><p>Dobrý den, {{df_salution|default('vážený zákazníku', true)}},</p><p>dlouho jste u nás nenakoupili. Podívejte se na novinky.</p><p><a href=\"https://www.example.cz/novinky\">Novinky</a></p><p style=\"font-size:12px\">{{cl_company}}, {{cl_address}}. <a href=\"{{unsubscribe}}\">Odhlásit odběr</a></p></body></html>"
  }
}
JSON
Odpoveď: 201 Created
{
  "id": "306",
  "name": "Win-back 1",
  "subject": "Chybíte nám",
  "preheader": "Podívejte se, co je u nás nového",
  "editor": "html",
  "createdAt": "2026-10-01T08:00:00.000Z",
  "updatedAt": "2026-10-01T08:00:00.000Z",
  "tags": [],
  "size": 346,
  "archived": false,
  "archivedAt": null,
  "readOnly": false,
  "usage": {
    "campaigns": 0,
    "automations": 0
  },
  "lastUsedAt": null,
  "check": {
    "errors": [],
    "warnings": [],
    "checkedAt": "2026-10-01T08:00:00.000Z"
  },
  "content": {
    "editor": "html",
    "html": "<!doctype html><html><body><p>Dobrý den, {{df_salution|default('vážený zákazníku', true)}},</p><p>dlouho jste u nás nenakoupili. Podívejte se na novinky.</p><p><a href=\"https://www.example.cz/novinky\">Novinky</a></p><p style=\"font-size:12px\">{{cl_company}}, {{cl_address}}. <a href=\"{{unsubscribe}}\">Odhlásit odběr</a></p></body></html>",
    "design": null,
    "version": 1,
    "updatedAt": "2026-10-01T08:00:00.000Z"
  },
  "settings": {
    "linkParams": [],
    "headers": [],
    "unsubscribePageId": null,
    "footerId": null
  },
  "draft": {
    "pending": false,
    "savedAt": null,
    "publishedAt": null
  },
  "activeUses": {
    "automations": 0,
    "emails": 0,
    "campaigns": 0
  },
  "publicUrl": "https://links.example.cz/template/11/1e8cfd05-8113-4e6b-9676-ad3dee1e849c"
}
Požiadavka: POST /api/v1/tenants/{tenant}/templates
curl -sS -X POST "https://www.postarna.cz/api/v1/tenants/$TENANT/templates" \
  -H "Authorization: Bearer $POSTARNA_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "name": "Win-back 2",
  "subject": "Poslední připomenutí",
  "preheader": "Doprava zdarma jen tento týden",
  "content": {
    "editor": "html",
    "design": null,
    "html": "<!doctype html><html><body><p>Dobrý den, {{df_salution|default('vážený zákazníku', true)}},</p><p>tento týden pro vás máme dopravu zdarma.</p><p style=\"font-size:12px\">{{cl_company}}, {{cl_address}}. <a href=\"{{unsubscribe}}\">Odhlásit odběr</a></p></body></html>"
  }
}
JSON
Odpoveď: 201 Created
{
  "id": "307",
  "name": "Win-back 2",
  "subject": "Poslední připomenutí",
  "preheader": "Doprava zdarma jen tento týden",
  "editor": "html",
  "createdAt": "2026-10-01T08:00:00.000Z",
  "updatedAt": "2026-10-01T08:00:00.000Z",
  "tags": [],
  "size": 273,
  "archived": false,
  "archivedAt": null,
  "readOnly": false,
  "usage": {
    "campaigns": 0,
    "automations": 0
  },
  "lastUsedAt": null,
  "check": {
    "errors": [],
    "warnings": [],
    "checkedAt": "2026-10-01T08:00:00.000Z"
  },
  "content": {
    "editor": "html",
    "html": "<!doctype html><html><body><p>Dobrý den, {{df_salution|default('vážený zákazníku', true)}},</p><p>tento týden pro vás máme dopravu zdarma.</p><p style=\"font-size:12px\">{{cl_company}}, {{cl_address}}. <a href=\"{{unsubscribe}}\">Odhlásit odběr</a></p></body></html>",
    "design": null,
    "version": 1,
    "updatedAt": "2026-10-01T08:00:00.000Z"
  },
  "settings": {
    "linkParams": [],
    "headers": [],
    "unsubscribePageId": null,
    "footerId": null
  },
  "draft": {
    "pending": false,
    "savedAt": null,
    "publishedAt": null
  },
  "activeUses": {
    "automations": 0,
    "emails": 0,
    "campaigns": 0
  },
  "publicUrl": "https://links.example.cz/template/11/8857a9fd-878f-4149-9ad1-55f5c0ae4115"
}

2. Automatizácia

Požiadavka: POST /api/v1/tenants/{tenant}/automations
curl -sS -X POST "https://www.postarna.cz/api/v1/tenants/$TENANT/automations" \
  -H "Authorization: Bearer $POSTARNA_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "name": "Win-back po 120 dnech",
  "shopId": "21",
  "graph": {
    "nodes": [
      {
        "id": "kazdy-den",
        "type": "trigger_repeat",
        "config": {
          "every": {
            "value": 1,
            "unit": "days"
          },
          "startAt": "2026-10-02T10:00",
          "reentry": "once",
          "filter": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "last_order",
                "operator": "older_than_days",
                "value": "120",
                "shopId": "21"
              },
              {
                "type": "order_count",
                "operator": "gte",
                "value": "1",
                "shopId": "21"
              }
            ]
          }
        }
      },
      {
        "id": "email-1",
        "type": "send_email",
        "config": {
          "templateId": "306"
        }
      },
      {
        "id": "tyden",
        "type": "wait",
        "config": {
          "mode": "duration",
          "value": 7,
          "unit": "days"
        }
      },
      {
        "id": "nakoupil",
        "type": "condition",
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "operator": "yes",
                "shopId": "21"
              }
            ]
          }
        }
      },
      {
        "id": "email-2",
        "type": "send_email",
        "config": {
          "templateId": "307"
        }
      },
      {
        "id": "cil",
        "type": "goal",
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "operator": "yes",
                "shopId": "21"
              }
            ]
          }
        }
      }
    ],
    "edges": [
      {
        "source": "kazdy-den",
        "target": "email-1"
      },
      {
        "source": "email-1",
        "target": "tyden"
      },
      {
        "source": "tyden",
        "target": "nakoupil"
      },
      {
        "source": "nakoupil",
        "target": "email-2",
        "branch": "no"
      }
    ]
  }
}
JSON
Odpoveď: 201 Created
{
  "id": "85",
  "name": "Win-back po 120 dnech",
  "shopId": "21",
  "status": "draft",
  "version": 1,
  "activeSince": null,
  "firstActivatedAt": null,
  "pausedReason": null,
  "tags": [],
  "createdAt": "2026-10-01T08:00:00.000Z",
  "updatedAt": "2026-10-01T08:00:00.000Z",
  "stats": {
    "entered": 0,
    "active": 0,
    "sent": 0
  },
  "description": "",
  "graph": {
    "nodes": [
      {
        "id": "kazdy-den",
        "type": "trigger_repeat",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "every": {
            "unit": "days",
            "value": 1
          },
          "filter": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "last_order",
                "value": "120",
                "shopId": "21",
                "operator": "older_than_days"
              },
              {
                "type": "order_count",
                "value": "1",
                "shopId": "21",
                "operator": "gte"
              }
            ]
          },
          "reentry": "once",
          "startAt": "2026-10-02T10:00"
        }
      },
      {
        "id": "email-1",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "306"
        }
      },
      {
        "id": "tyden",
        "type": "wait",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "mode": "duration",
          "unit": "days",
          "value": 7
        }
      },
      {
        "id": "nakoupil",
        "type": "condition",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      },
      {
        "id": "email-2",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "307"
        }
      },
      {
        "id": "cil",
        "type": "goal",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      }
    ],
    "edges": [
      {
        "source": "kazdy-den",
        "target": "email-1",
        "branch": "next"
      },
      {
        "source": "email-1",
        "target": "tyden",
        "branch": "next"
      },
      {
        "source": "tyden",
        "target": "nakoupil",
        "branch": "next"
      },
      {
        "source": "nakoupil",
        "target": "email-2",
        "branch": "no"
      }
    ]
  },
  "issues": [],
  "triggers": {}
}

Detail ukazuje graf, ako ho server uložil (s východiskovými hodnotami) a issues (prázdne = dá sa zapnúť):

Požiadavka: GET /api/v1/tenants/{tenant}/automations/85
curl -sS -X GET "https://www.postarna.cz/api/v1/tenants/$TENANT/automations/85" \
  -H "Authorization: Bearer $POSTARNA_API_KEY"
Odpoveď: 200 OK
{
  "id": "85",
  "name": "Win-back po 120 dnech",
  "shopId": "21",
  "status": "draft",
  "version": 1,
  "activeSince": null,
  "firstActivatedAt": null,
  "pausedReason": null,
  "tags": [],
  "createdAt": "2026-10-01T08:00:00.000Z",
  "updatedAt": "2026-10-01T08:00:00.000Z",
  "stats": {
    "entered": 0,
    "active": 0,
    "sent": 0
  },
  "description": "",
  "graph": {
    "nodes": [
      {
        "id": "kazdy-den",
        "type": "trigger_repeat",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "every": {
            "unit": "days",
            "value": 1
          },
          "filter": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "last_order",
                "value": "120",
                "shopId": "21",
                "operator": "older_than_days"
              },
              {
                "type": "order_count",
                "value": "1",
                "shopId": "21",
                "operator": "gte"
              }
            ]
          },
          "reentry": "once",
          "startAt": "2026-10-02T10:00"
        }
      },
      {
        "id": "email-1",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "306"
        }
      },
      {
        "id": "tyden",
        "type": "wait",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "mode": "duration",
          "unit": "days",
          "value": 7
        }
      },
      {
        "id": "nakoupil",
        "type": "condition",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      },
      {
        "id": "email-2",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "307"
        }
      },
      {
        "id": "cil",
        "type": "goal",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      }
    ],
    "edges": [
      {
        "source": "kazdy-den",
        "target": "email-1",
        "branch": "next"
      },
      {
        "source": "email-1",
        "target": "tyden",
        "branch": "next"
      },
      {
        "source": "tyden",
        "target": "nakoupil",
        "branch": "next"
      },
      {
        "source": "nakoupil",
        "target": "email-2",
        "branch": "no"
      }
    ]
  },
  "issues": [],
  "triggers": {}
}

3. Zapnutie, pozastavenie a verzie

Požiadavka: POST /api/v1/tenants/{tenant}/automations/85/activate
curl -sS -X POST "https://www.postarna.cz/api/v1/tenants/$TENANT/automations/85/activate" \
  -H "Authorization: Bearer $POSTARNA_API_KEY"
Odpoveď: 200 OK
{
  "id": "85",
  "name": "Win-back po 120 dnech",
  "shopId": "21",
  "status": "active",
  "version": 1,
  "activeSince": "2026-10-01T08:00:00.000Z",
  "firstActivatedAt": "2026-10-01T08:00:00.000Z",
  "pausedReason": null,
  "tags": [],
  "createdAt": "2026-10-01T08:00:00.000Z",
  "updatedAt": "2026-10-01T08:00:00.000Z",
  "stats": {
    "entered": 0,
    "active": 0,
    "sent": 0
  },
  "description": "",
  "graph": {
    "nodes": [
      {
        "id": "kazdy-den",
        "type": "trigger_repeat",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "every": {
            "unit": "days",
            "value": 1
          },
          "filter": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "last_order",
                "value": "120",
                "shopId": "21",
                "operator": "older_than_days"
              },
              {
                "type": "order_count",
                "value": "1",
                "shopId": "21",
                "operator": "gte"
              }
            ]
          },
          "reentry": "once",
          "startAt": "2026-10-02T10:00"
        }
      },
      {
        "id": "email-1",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "306"
        }
      },
      {
        "id": "tyden",
        "type": "wait",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "mode": "duration",
          "unit": "days",
          "value": 7
        }
      },
      {
        "id": "nakoupil",
        "type": "condition",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      },
      {
        "id": "email-2",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "307"
        }
      },
      {
        "id": "cil",
        "type": "goal",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      }
    ],
    "edges": [
      {
        "source": "kazdy-den",
        "target": "email-1",
        "branch": "next"
      },
      {
        "source": "email-1",
        "target": "tyden",
        "branch": "next"
      },
      {
        "source": "tyden",
        "target": "nakoupil",
        "branch": "next"
      },
      {
        "source": "nakoupil",
        "target": "email-2",
        "branch": "no"
      }
    ]
  },
  "issues": [],
  "triggers": {}
}

Pozastavenie necháva čakajúce kontakty na mieste; po ďalšom zapnutí pokračujú:

Požiadavka: POST /api/v1/tenants/{tenant}/automations/85/pause
curl -sS -X POST "https://www.postarna.cz/api/v1/tenants/$TENANT/automations/85/pause" \
  -H "Authorization: Bearer $POSTARNA_API_KEY"
Odpoveď: 200 OK
{
  "id": "85",
  "name": "Win-back po 120 dnech",
  "shopId": "21",
  "status": "paused",
  "version": 1,
  "activeSince": null,
  "firstActivatedAt": "2026-10-01T08:00:00.000Z",
  "pausedReason": "manual",
  "tags": [],
  "createdAt": "2026-10-01T08:00:00.000Z",
  "updatedAt": "2026-10-01T08:00:00.000Z",
  "stats": {
    "entered": 0,
    "active": 0,
    "sent": 0
  },
  "description": "",
  "graph": {
    "nodes": [
      {
        "id": "kazdy-den",
        "type": "trigger_repeat",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "every": {
            "unit": "days",
            "value": 1
          },
          "filter": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "last_order",
                "value": "120",
                "shopId": "21",
                "operator": "older_than_days"
              },
              {
                "type": "order_count",
                "value": "1",
                "shopId": "21",
                "operator": "gte"
              }
            ]
          },
          "reentry": "once",
          "startAt": "2026-10-02T10:00"
        }
      },
      {
        "id": "email-1",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "306"
        }
      },
      {
        "id": "tyden",
        "type": "wait",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "mode": "duration",
          "unit": "days",
          "value": 7
        }
      },
      {
        "id": "nakoupil",
        "type": "condition",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      },
      {
        "id": "email-2",
        "type": "send_email",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "templateId": "307"
        }
      },
      {
        "id": "cil",
        "type": "goal",
        "name": "",
        "note": "",
        "position": {
          "x": 0,
          "y": 0
        },
        "config": {
          "definition": {
            "type": "group",
            "match": "all",
            "rules": [
              {
                "type": "ordered_since_entry",
                "shopId": "21",
                "operator": "yes"
              }
            ]
          }
        }
      }
    ],
    "edges": [
      {
        "source": "kazdy-den",
        "target": "email-1",
        "branch": "next"
      },
      {
        "source": "email-1",
        "target": "tyden",
        "branch": "next"
      },
      {
        "source": "tyden",
        "target": "nakoupil",
        "branch": "next"
      },
      {
        "source": "nakoupil",
        "target": "email-2",
        "branch": "no"
      }
    ]
  },
  "issues": [],
  "triggers": {}
}
Požiadavka: GET /api/v1/tenants/{tenant}/automations/85/versions
curl -sS -X GET "https://www.postarna.cz/api/v1/tenants/$TENANT/automations/85/versions" \
  -H "Authorization: Bearer $POSTARNA_API_KEY"
Odpoveď: 200 OK
{
  "items": [
    {
      "version": 1,
      "status": "draft",
      "savedAt": "2026-10-01T08:00:00.000Z",
      "savedBy": "api_key:11",
      "nodes": 6,
      "current": true
    }
  ]
}

Tipy

  • Filter spúšťača počíta dni v časovej zóne firmy; last_order older_than_days 120 znamená „má objednávku a posledná je staršia než 120 dní“.
  • Pre neotvárajúcich odberateľov (namiesto zákazníkov) použite pravidlo field lastOpenAt not_in_last_days "180".
  • Odmenu v druhom e-maile dajte jednorazovým kódom (data.promoCode), pozrite recept na meniny.