smartchat

Eine Automation bauen

Du brauchst die Rechte automations:read und automations:write, um einen Entwurf zu lesen und vorzubereiten. Das Einschalten einer Automation braucht automations:run (ein Schlüssel mit der Stufe Draft kann das nicht). Dasselbe gilt für das Ändern des Auslösers, der Schritte oder der Regeln einer Automation, die schon läuft. Schritte, die eine Adresse aufrufen, brauchen webhooks:write; Schritte in verbundenen Apps brauchen connections:run.

#1. Den Katalog lesen

Der Katalog listet die Auslöser, Aktionen und Regeln, die du nutzen kannst. Baue nur aus dem, was im Katalog steht.

curl "https://api.smartchat.marketing/v1/automation-catalog" \
  -H "Authorization: Bearer $SMARTCHAT_API_KEY"
import os
import requests

response = requests.get(
    "https://api.smartchat.marketing/v1/automation-catalog",
    headers={"Authorization": "Bearer " + os.environ["SMARTCHAT_API_KEY"]},
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.smartchat.marketing/v1/automation-catalog", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.SMARTCHAT_API_KEY}`,
  },
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());

Response (200):

{
  "object": "automation_catalog",
  "version": "2d26379cee484580",
  "triggers": [
    {
      "type": "signup",
      "group": "contact",
      "description": "Starts when a contact signs up.",
      "fields": [],
      "allowed_as_further_trigger": true
    }
  ]
}

#2. Als Entwurf anlegen

Eine Automation ohne status ist ein Entwurf. Sie tut noch nichts.

curl -X POST "https://api.smartchat.marketing/v1/automations" \
  -H "Authorization: Bearer $SMARTCHAT_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Welcome after signup",
  "trigger": {
    "type": "signup"
  },
  "steps": [
    {
      "type": "send_message",
      "text": "Hello {{name}}, nice to have you with us."
    },
    {
      "type": "wait",
      "minutes": 1440
    },
    {
      "type": "add_tag",
      "tag": "welcomed"
    }
  ]
}'
import os
import uuid
import requests

response = requests.post(
    "https://api.smartchat.marketing/v1/automations",
    headers={
        "Authorization": "Bearer " + os.environ["SMARTCHAT_API_KEY"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "name": "Welcome after signup",
        "trigger": {
            "type": "signup",
        },
        "steps": [
            {
                "type": "send_message",
                "text": "Hello {{name}}, nice to have you with us.",
            },
            {
                "type": "wait",
                "minutes": 1440,
            },
            {
                "type": "add_tag",
                "tag": "welcomed",
            },
        ],
    },
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.smartchat.marketing/v1/automations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SMARTCHAT_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "Welcome after signup",
    "trigger": {
      "type": "signup"
    },
    "steps": [
      {
        "type": "send_message",
        "text": "Hello {{name}}, nice to have you with us."
      },
      {
        "type": "wait",
        "minutes": 1440
      },
      {
        "type": "add_tag",
        "tag": "welcomed"
      }
    ]
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());

Response (201):

{
  "object": "automation",
  "id": "aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234",
  "name": "Welcome after signup",
  "status": "draft",
  "draft": true,
  "trigger": {
    "type": "signup"
  },
  "steps": [
    {
      "type": "send_message",
      "id": "s_1",
      "text": "Hello {{name}}, nice to have you with us.",
      "template": {
        "id": null,
        "status": "draft"
      }
    },
    {
      "type": "wait",
      "id": "s_2",
      "minutes": 1440
    },
    {
      "type": "add_tag",
      "id": "s_3",
      "tag": "welcomed"
    }
  ],
  "rules": {
    "max_per_contact": null,
    "excluded_names": []
  },
  "has_inbound_webhook": false,
  "notices": [],
  "run_count": 0,
  "last_run_at": null,
  "created_at": "2026-10-30T09:41:07Z",
  "updated_at": "2026-10-30T09:41:07Z"
}

Verletzt die Automation eine Regel des Katalogs (zum Beispiel hat sie zu viele Schritte), lautet die Antwort automation_invalid und listet jedes Problem in errors.

#3. Einschalten

Dieser Schritt braucht das Recht automations:run. Ohne es lautet die Antwort 403 insufficient_scope und required_scope ist automations:run. Lege einen Schlüssel mit der Stufe All an oder hake das Recht an.

curl -X PUT "https://api.smartchat.marketing/v1/automations/aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234/status" \
  -H "Authorization: Bearer $SMARTCHAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "status": "active"
}'
import os
import requests

response = requests.put(
    "https://api.smartchat.marketing/v1/automations/aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234/status",
    headers={"Authorization": "Bearer " + os.environ["SMARTCHAT_API_KEY"]},
    json={
        "status": "active",
    },
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.smartchat.marketing/v1/automations/aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234/status", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.SMARTCHAT_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "status": "active"
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());

Response (200):

{
  "object": "automation",
  "id": "aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234",
  "name": "Welcome after signup",
  "status": "active",
  "draft": false,
  "trigger": {
    "type": "signup"
  },
  "steps": [
    {
      "type": "send_message",
      "id": "s_1",
      "text": "Hello {{name}}, nice to have you with us.",
      "template": {
        "id": null,
        "status": "draft"
      }
    },
    {
      "type": "wait",
      "id": "s_2",
      "minutes": 1440
    },
    {
      "type": "add_tag",
      "id": "s_3",
      "tag": "welcomed"
    }
  ],
  "rules": {
    "max_per_contact": null,
    "excluded_names": []
  },
  "has_inbound_webhook": false,
  "notices": [],
  "run_count": 0,
  "last_run_at": null,
  "created_at": "2026-10-30T09:41:07Z",
  "updated_at": "2026-10-30T09:41:07Z"
}

Du darfst eine Automation einschalten, auch wenn eine Vorlage darin noch nicht genehmigt ist. Nachrichten, die die Vorlage brauchen, warten, bis sie genehmigt ist. Siehe Entwürfe und Aktivierung.

#4. Die Läufe beobachten

curl "https://api.smartchat.marketing/v1/automations/aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234/runs?limit=1" \
  -H "Authorization: Bearer $SMARTCHAT_API_KEY"
import os
import requests

response = requests.get(
    "https://api.smartchat.marketing/v1/automations/aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234/runs",
    headers={"Authorization": "Bearer " + os.environ["SMARTCHAT_API_KEY"]},
    params={
        "limit": "1",
    },
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.smartchat.marketing/v1/automations/aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234/runs?limit=1", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.SMARTCHAT_API_KEY}`,
  },
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());

Response (200):

{
  "object": "list",
  "data": [
    {
      "object": "automation_run",
      "id": "run_1a2b3c4d5e6f40718293a4b5c6d7e8f9",
      "automation_id": "aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234",
      "status": "executed",
      "created_at": "2026-10-30T09:41:07Z"
    }
  ],
  "has_more": false,
  "next_cursor": null,
  "url": "/v1/automations/aut_0f8c1a2e4b7d4c3e9a5b6d7e8f901234/runs"
}