Using the web API¶
Everything the web application does, it does through FlowAssembly’s web API,
and other systems can use the same API. It is JSON over HTTPS, under
/api/v0. The Web API reference lists every
operation. Its OpenAPI description, to generate a client from, is
openapi.yaml.
This guide is for developers connecting another system: a portal that starts cases, a core system that moves them on, a report that reads them.
An account for the system¶
A system signs in as people do, with an account of its own:
a local account (Admin > Users > User list), or a service account in the directory;
in a group the access policy gives only what the system needs. A portal that sends applications needs
runtime.messagein its project, and nothing else.
Everything it does is recorded under that account, like a person’s.
Signing in¶
Each change needs the CSRF token, in the X-CSRFToken header, and the
session cookie. Signing in gives a new token.
base=https://flowassembly.bank.example
jar=$(mktemp)
# 1. A token to sign in with.
token=$(curl -s -c "$jar" "$base/api/v0/session" | jq -r .csrf_token)
# 2. Sign in; keep the new token.
token=$(curl -s -b "$jar" -c "$jar" -H "X-CSRFToken: $token" \
-H "Content-Type: application/json" -X POST "$base/api/v0/session" \
-d '{"username": "loans-portal", "password": "'"$PORTAL_PASSWORD"'"}' | jq -r .csrf_token)
In Python:
import requests
base = "https://flowassembly.bank.example"
api = requests.Session()
token = api.get(f"{base}/api/v0/session").json()["csrf_token"]
signed_in = api.post(f"{base}/api/v0/session", headers={"X-CSRFToken": token},
json={"username": "loans-portal", "password": PORTAL_PASSWORD})
signed_in.raise_for_status()
api.headers["X-CSRFToken"] = signed_in.json()["csrf_token"]
A session ends after 30 minutes without a call, 12 hours after signing in, or when the account is disabled. A call then answers 401, and the system signs in again. Keep the password in the system’s own secret store.
Sending a message to a case¶
A message reaches the case waiting for it, matched by the fields the process correlates on, or starts a case if the process starts on it:
answer = api.post(f"{base}/api/v0/projects/agent-loans/messages/application_received",
json={"payload": {"application_id": "APP-1042", "amount": 250000,
"branch": "Yaba"}})
It answers:
201 when it started a case;
200 when a case received it;
202 when it is kept until a case is ready for it.
kept_untilsays until when, if the project lets early messages wait.
Each answer lists the ids of the cases it started (started) and of the
cases that received it (delivered). A message that starts a case starts one
each time it is sent, so send each once. A message to a waiting case reaches
only the case whose correlating fields it matches.
A system that signs its posts rather than signing in uses the project’s webhook instead (Connecting other systems).
Starting and moving cases on¶
case = api.post(f"{base}/api/v0/projects/agent-loans/cases",
json={"process": "loan_application", "data": {"amount": 250000}}).json()
for task in api.get(f"{base}/api/v0/inbox").json()["tasks"]:
...
api.post(f"{base}/api/v0/cases/{task['case_id']}/tasks/{task['task_id']}",
json={"data": {"approved": True}})
When something is refused¶
Every refusal is JSON, with a code that stays the same and a message to show people:
{"error": "form_invalid", "message": "Some fields need attention",
"fields": {"amount": "Must be at most 5000000"}}
Status |
|
Means |
|---|---|---|
400 |
|
The call is not as the operation says |
401 |
|
Sign in (again) |
403 |
|
The account may not do this, or the CSRF token is missing. Refusals are recorded. |
404 |
|
No such case, task or page, or not one this account may see |
409 |
|
Not now: the task is done or someone else has it, the case is suspended, or the data changed since |
413 |
|
A file or post over its limit |
422 |
|
|
429 |
|
Too many failed sign-ins from this address; wait |
Pages of results¶
Lists that can be long take limit. Their answers say where the next page
starts (next, to pass back as after), or whether there are more
(more).
Versions¶
The API is version 0 (/api/v0). Until version 1, an operation can change
between FlowAssembly versions; each version’s notes say what changed, and the
reference here is always the one for the version this instance runs. Every
answer the platform’s own tests receive is checked against the OpenAPI
description, so the description matches the API.