Build, change and switch automations on and off from your own tools, with the same JSON the editor in the app uses. Anything you make here can be opened under Messaging > Automations (see Automations). You can also start an automation from your system with an event, such as "order shipped".
List and read automations
GET https://gdwaapi.grapedawn.tech/api/v1/automationsreturns every automation.GET https://gdwaapi.grapedawn.tech/api/v1/automations/:idreturns one, or a 404Automation not found.
curl https://gdwaapi.grapedawn.tech/api/v1/automations \
-H "Authorization: Bearer lms_your_key"
Each automation has id, name, trigger, steps (and triggers, conditions and rules when it has them), plus:
| Field | What it is |
|---|---|
status | DRAFT, ACTIVE or PAUSED |
problems | Why it cannot be switched on as it stands, such as Step 3: .... Empty when it can |
runs | Counts of active, finished, stopped and failed runs |
updatedBy | Who last changed it in the app, or null when it was changed with a key |
createdAt, updatedAt | ISO times |
Create and change one
POST https://gdwaapi.grapedawn.tech/api/v1/automationscreates one from{ name, trigger, steps }. It is always saved as a draft, switched off.PUT https://gdwaapi.grapedawn.tech/api/v1/automations/:idreplaces its name, trigger and steps with the body you send. Send the whole automation, not only what changed.
curl https://gdwaapi.grapedawn.tech/api/v1/automations \
-H "Authorization: Bearer lms_your_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Price enquiry",
"trigger": { "type": "keyword", "keywords": ["price", "fees"] },
"steps": [
{ "id": "hello", "type": "send_text", "text": "Hi {{name}}! Our plans start at 999 rupees a month.", "next": "toSales" },
{ "id": "toSales", "type": "assign", "userId": "3f2c9a1e-5b7d-4e8f-a0b1-c2d3e4f5a6b7", "next": null }
]
}'
The answer is the saved automation. Read its problems, fix them, and PUT again until the list is empty. When you change an existing automation, GET it first and keep each step's id, since runs in progress follow step ids. A body the api cannot read is refused with a 422 naming what is wrong. A business can have up to 100 automations.
The automation JSON
An automation is a trigger, an optional triggers list of more things that start it, and 1 to 30 steps. The first step is where a run begins.
trigger is one of:
{ "type": "first_message" }: a contact's first ever message.{ "type": "keyword", "keywords": ["price"] }: a message with any of these words or phrases.{ "type": "manual" }: only when someone starts it on a chat in the app.
triggers can add others, such as { "type": "api_event", "event": "order.shipped" } (see Send an automation event).
Each step has a unique id you choose, a type, and next: the id of the step to go to, null to end the run, or left out to go to the step below. The step types include send_text, send_template, send_file, wait, wait_for_reply, ask (buttons, a list or a form, then branch on the answer), assign, api_call and ai_reply, as well as tags, if, set_stage, set_follow_up, add_note and update_contact.
Text can hold {{name}}, {{phone}} and values kept by earlier steps. Any free-form step that could run 24 hours or more after the contact last wrote needs a fallback template, or problems will say so. To see the exact fields of any step, build it in the editor in the app, then read the automation back with GET: the api returns the same JSON it accepts.
Switch on, pause and delete
POST https://gdwaapi.grapedawn.tech/api/v1/automations/:id/activateswitches it on. It is refused with a 422 startingIt can't be switched on yet.while it has problems, and with a 402 when your plan does not allow another active automation, or a step it uses (api_call,ai_reply).POST https://gdwaapi.grapedawn.tech/api/v1/automations/:id/pauseswitches it off and stops its runs in progress.DELETE https://gdwaapi.grapedawn.tech/api/v1/automations/:iddeletes it and answers{"deleted": true}.
curl -X POST https://gdwaapi.grapedawn.tech/api/v1/automations/9d8e7f6a-5b4c-4d3e-8f2a-1b0c9d8e7f6a/activate \
-H "Authorization: Bearer lms_your_key"
An active automation messages real customers with nobody pressing send, so switch one on only once it has been checked.
See its runs
GET https://gdwaapi.grapedawn.tech/api/v1/automations/runs?automationId=<id> returns the latest 50 runs, newest first. Leave out automationId for runs of every automation.
Each run has id, automationId, automationName, contact (name, phone), status (RUNNING, WAITING, DONE, STOPPED, FAILED or SKIPPED), stepIndex (counted from 0), waitingFor (time, reply or null), wakeAt, reason (why it stopped or failed), log (a list of { at, text }), startedAt and updatedAt.
Send an automation event
POST https://gdwaapi.grapedawn.tech/api/v1/automation-events tells gdwa that something happened in your system, for one contact. It starts the best switched-on automation with an api_event trigger for that event.
| Field | Required | What it is |
|---|---|---|
event | Yes | Up to 60 letters, digits, dots, dashes or underscores, such as order.shipped. Matched in lowercase |
contactId | One of these two | The contact's id |
phone | One of these two | The phone number with its country code. A number that is not a contact yet becomes one |
data | No | A JSON object under 16 KB. The run's steps read it as {{event.…}}, such as {{event.order}} |
curl https://gdwaapi.grapedawn.tech/api/v1/automation-events \
-H "Authorization: Bearer lms_your_key" \
-H "Content-Type: application/json" \
-d '{"event": "order.shipped", "phone": "+919800000001", "data": {"order": "#1234"}}'
{
"contactId": "b2e4d6f8-1a3c-4e5f-8a9b-0c1d2e3f4a5b",
"started": "Shipping update"
}
started is the name of the automation that started, or null when none did: none listens for the event, its rules or conditions did not allow it, or a run is already going in that chat. The contact may not have written in 24 hours, so the automation's first message must be a template. Errors: 422 Give a contactId or a phone., 422 for a phone without a country code, 404 Contact not found, and 422 data must be under 16 KB.