The API covers the entire approval cycle: configuring a module’s workflow, requesting approval for a record, responding to steps, and tracking requests. The controls match those of the screens: whatever a screen rejects, the API rejects with the same reason. The same operations are available to the Kafinea AI assistant and to assistants connected to Kafinea.
All operations use the REST API session. Identifiers are those of the API (89x47808); a simple number is also accepted.
| Operation | Method | Who | Effect |
|---|---|---|---|
approval_circuit_read |
GET | administrator | Workflows, or a module’s workflow with its templates and expected format |
approval_circuit_configure |
POST | administrator | Check, save, enable, disable, or delete a workflow |
approval_circuit_simulate |
GET | administrator | What a workflow would require for 1 to 20 records, without saving anything |
approval_inbox |
GET | everyone | Items awaiting their response, their requests, and requests from others they are authorized to view |
approval_request_read |
GET | everyone | The approval of a record, as shown in its panel |
approval_request |
POST | everyone | Request approval for a record they can modify |
approval_answer |
POST | the approver | Their own response to a step assigned to them |
approval_cancel |
POST | requester or administrator | Cancel a pending request |
Request and response operations are available when the Approvals feature is active.
1. Configuring a workflow #
approval_circuit_read without parameters lists the workflows and modules that can receive one. With moduleName, it returns the module’s workflow (circuit, with its revision), the starting templates (templates), and the format of a workflow (contract).
curl -G 'https://apps.kafinea.com/YourKafinea/webservice.php' \
--data-urlencode 'operation=approval_circuit_read' \
--data-urlencode 'sessionName=YOUR_SESSION_ID' \
--data-urlencode 'moduleName=Quotes'
A workflow is described in its entirety:
{
"label": "Devis au-delà de 5 000 € HT",
"active": true,
"condition": [{"fieldname": "pre_tax_total", "operation": "greater than", "value": "5000", "groupid": "0"}],
"finalizeOnApproval": true,
"steps": [{
"label": "Responsable commercial",
"condition": [],
"approver": {"mode": "manager", "managerOf": "requester"},
"dueDays": 2,
"summaryTemplate": "Devis $subject : $pre_tax_total € HT"
}]
}
| Element | Content |
|---|---|
condition |
Records that must be approved, in the workflow condition format; [] for all. groupid 0: all these criteria; 1: at least one of them |
steps[].approver |
fixed with ownerId (a user or a group), manager with managerOf (requester or owner), or field with expression (for example assigned_user_id) |
steps[].condition |
Optional: a step whose condition is not met is skipped |
steps[].stepId |
To be returned as read: requests already made continue to name their step |
watchedFields |
Fields whose modification after approval makes it void, in addition to those read by conditions (always monitored); watchedLabels lists them all, with their labels |
approval_circuit_configure receives moduleName, action and, depending on the action, definition (the workflow in JSON) and revision:
action |
Effect |
|---|---|
validate |
Checks definition without saving anything and returns valid and the problems list (each with path, code and message) |
save |
Saves definition in full; revision is the one read, 0 to create the workflow for a module that does not have one |
activate, deactivate |
Enables or disables the workflow of the revision read |
delete |
Deletes the workflow; requests already made remain |
curl -X POST 'https://apps.kafinea.com/YourKafinea/webservice.php' \
--data-urlencode 'operation=approval_circuit_configure' \
--data-urlencode 'sessionName=YOUR_SESSION_ID' \
--data-urlencode 'moduleName=Quotes' \
--data-urlencode 'action=save' \
--data-urlencode 'revision=3' \
--data-urlencode 'definition={"label":"Devis au-delà de 5 000 € HT","active":true,…}'
An active workflow must be capable of being approved: each step has a valid approver. An inactive workflow can remain as a draft.
Before enabling, approval_circuit_simulate shows, for saved records (recordIds, a JSON list) and a requester (requesterId, the connected user by default), if the workflow condition is met and who would be solicited at each step, or why no one could respond (error). Pass definition to test a workflow before saving it. Nothing is saved or sent.
2. Requesting, responding, tracking #
approval_inbox returns, depending on box: toAnswer (steps awaiting the user’s response, directly or through one of their groups), requested (their requests), or others (other pending requests they are authorized to view). Without box, all three. Each step to be processed carries its lineId.
approval_request_read with recordId returns the record’s current request, its steps (approver, response, reason, canAnswer for the one the user can respond to) and wouldAsk: what a new request would solicit.
approval_request with recordId requests approval on behalf of the connected user. It is rejected when nothing requires approval or when a request is already pending.
approval_answer receives lineId, answer (approve, refuse or changes) and reason, mandatory for rejecting or requesting modifications:
curl -X POST 'https://apps.kafinea.com/YourKafinea/webservice.php' \
--data-urlencode 'operation=approval_answer' \
--data-urlencode 'sessionName=YOUR_SESSION_ID' \
--data-urlencode 'lineId=194x48180' \
--data-urlencode 'answer=approve'
The response is always that of the connected user: no parameter designates another user. It is rejected when the step is not assigned to this user or to one of their groups (including administrators), when it is their own request, or when another member of the group has already responded.
approval_cancel with approvalId cancels a pending request: by its requester or an administrator.
3. Record approval status #
Each record of a module that has a workflow carries the read-only field mdsapprovalstatus: empty as long as no approval has been requested, then APPROVAL_STATUS_PENDING, APPROVAL_STATUS_APPROVED, APPROVAL_STATUS_REFUSED, APPROVAL_STATUS_CHANGES_REQUESTED, APPROVAL_STATUS_CANCELLED or APPROVAL_STATUS_OBSOLETE (void approval). It is read like any field, with retrieve or query:
curl -G 'https://apps.kafinea.com/YourKafinea/webservice.php' \
--data-urlencode 'operation=query' \
--data-urlencode 'sessionName=YOUR_SESSION_ID' \
--data-urlencode "query=SELECT potentialname, amount FROM Potentials WHERE mdsapprovalstatus = 'APPROVAL_STATUS_APPROVED';"
Only approvals write to it. An approval becomes void when a monitored field of the record subsequently changes; the request then keeps the reason in its description.
4. Rejections #
A rejection starts with its code, followed by the readable reason:
| Code | Meaning |
|---|---|
APPROVAL_CIRCUIT_INVALID |
The workflow is not valid; each problem follows, one line per problem, with its path and code |
APPROVAL_CIRCUIT_REVISION_CHANGED |
The workflow has changed since it was read: re-read it, then perform the modification again |
APPROVAL_CIRCUIT_NOT_FOUND, APPROVAL_CIRCUIT_EXISTS |
The module has no workflow, or already has one |
APPROVAL_REFUSED |
The request, response, or cancellation is not permitted; the reason is the one displayed on the screen |
APPROVAL_FEATURE_DISABLED |
The Approvals feature is not active |
ACCESS_DENIED |
The operation is restricted to administrators |