Use cases

Triggering another system and getting the result back

Sometimes a task in a case is done by another program rather than a person, such as an accounting system. Bricksta reports the work, waits and continues once the result is back. Both directions use REST. Nothing in Bricksta is programmed for this, you only configure it.

On this page

Setting it up in Bricksta

You need: the permission to administer the organization, for the API access. For the template and the webhook you need the permission to manage templates. From the other system you need a publicly reachable address.

  1. 1
    Create an access under Organization › Interfaces › API access. Choose a permission profile that may edit and complete tasks.
  2. 2
    In the same window, choose a role under Roles, for example Accounting system. If it doesn't exist yet, create it first under Organization › Roles.
  3. 3
    Copy the key and hand it to the other system. Bricksta shows it only this once.
  4. 4
    Add the task to the template. Make the role its owner and give it fields for the result, for example Invoice number.
  5. 5
    Create a webhook under Automation → Outbound: your template, the event Task ready and the system's address.
  6. 6
    Expand the webhook. Create a secret with generate and check the connection with Send test.
The form for creating an outbound webhook with name, template, event and target URL.
  1. 1Event: choose Task ready here
  2. 2Address of the other system
The webhook reports every task of the template to the other system as soon as it is open.

Result: as soon as a case reaches the task, Bricksta reports the task to the other system. It waits until the system writes the result back and completes it.

Without a secret there is no signature, and the other system can't check where a report comes from. The test from Send test never carries an identifier or signature.

Report, fetch, result, completion

An example: after an order is approved, the accounting system should create an invoice. The case needs the invoice number afterwards. So the task “Create invoice” belongs to the accounting system.

The accounting system gets its own access to Bricksta, an API access. It works like a member: it holds a role, sees the tasks of that role and completes them.

Flow
Bricksta                                   other system
1. Task becomes open
   POST to the system's address     ─────►  “Task 123 is ready”
                                    ◄─────  2. GET /api/v1/tasks       (list, locks every task in it)
                                    ◄─────     GET /api/v1/tasks/123   (fields of the task)
                                            3. does the work
                                    ◄─────  4. PUT /api/v1/tasks/123/values/{field_id}
                                    ◄─────  5. POST /api/v1/tasks/123/complete
6. Task done, the flow continues
  • Bricksta sends only identifiers, no content. Only a caller signed in with the key gets field values.
  • The list holds the tasks the API access may work on and that nobody holds right now. It locks each of them and comes in pages: keep paging until next_cursor is empty.
  • The task in Bricksta waits, even for days. The system's lock, however, lasts one hour at most and is not extended.
  • Only completing the task releases the flow, just like a person ticking it off.

What the other system has to do

This part is built by the vendor or IT provider of the other system. Every call to Bricksta carries the key from the API access.

Accept the reportPOST from Bricksta to the system's addressAnswer within ten seconds with a status from 200 to 299. Check the signature and process each event_id only once.
Fetch the taskGET /api/v1/tasksLook for the task from the report in the list. If it's missing, it belongs to someone else, is locked, blocked or awaiting approval. lock_duration sets the lock time.
Read the fieldsGET /api/v1/tasks/{id}Returns the fields of the task with their IDs and current values.
Save the resultPUT /api/v1/tasks/{id}/values/{field_id}One call per field, with the Idempotency-Key header, plus lock_token and run_no in the body. A retry writes the value again.
CompletePOST /api/v1/tasks/{id}/completeWith the Idempotency-Key header. Retrying with the same key is safe.
Report from Bricksta
{
  "event": "task_ready",
  "event_id": "8b0e3c1a-…",
  "case_id": "5f2d9e70-…",
  "task_id": "c41a7b22-…",
  "run_no": 1
}

If something doesn't work

The Outbound page with the creation form at the top and an existing webhook below, showing template, event and status.
Each webhook lists its recent runs with the status the other system answered with.
The report gets no answer or status 500 and above, 408, 425, 429Bricksta tries up to three times. Look under Recent runs on the webhook, the address must be publicly reachable.
The report gets status 400 or 404Bricksta doesn't try again. The error is under Recent runs, check the address.
The list doesn't contain the taskCheck that the API access holds the owning role and nobody has assigned the task to a person. Locked, blocked and tasks awaiting approval are missing too.
Response 403 not_assignedThe task belongs to a person or a role the API access doesn't hold.
Response 409 task_blocked or task_in_approvalThe task is blocked or waiting for an approval. The API cannot approve, that happens in Bricksta.
Response 409 task_locked or run_mismatchAnother instance fetched the task after the lock expired, or a step back reopened it. The system fetches it again.
Response 422 required_fields_missingRequired fields are missing. The response names them, the system fills them and completes again.
The task is never completedIt stays open. Give it a deadline, so you see in Bricksta when it is stuck.

What's next?