Finance · Cash · Transactions
Update cash transaction rule
Replaces the name, matching conditions (matcher), outcome and positions of an existing cash transaction rule in the mandate. The rule stays in its mandate. It acts on transactions that come in afterwards, and on existing ones only when it is run again. Proposals it already made stay as they are. Before saving, the new conditions and positions are checked against the mandate's bank accounts and the organization's accounting plan. Nothing is returned.
Permissions
Send an API key of the organization in the path, using the X-API-Key header.
Who may call it
- Callers need the
mandate.readandcashTransactionRule.editpermissions. - Rules apply automatically to new transactions. So the caller also needs the permissions that the chosen
outcome(postingReceiptordonationProposal) requires.
Request
Path parameters
-
organizationIdidrequired -
mandateIdidrequiredThe mandate the rule belongs to; if the rule is not in this mandate, the request fails as not found.
-
cashTransactionRuleIdidrequiredThe cash transaction rule to update.
Body
Content-Type: application/json
-
outcomestringrequiredWhat the rule creates for a matching transaction: a posting receipt or a donation proposal, and the caller also needs the permissions that this outcome requires.
postingReceiptdonationProposal -
namestringnullableThe name of the rule, which is removed when this field is left out.
1–100 characters
-
matcherobjectrequiredThe conditions a transaction must meet for the rule to apply, of which at least one must be set.
6 properties
-
typeMatchstringrequiredWhether the rule applies to revenue or expense transactions; with the
postingReceiptoutcome it also decides which kinds of account thepositionsmay use.revenueexpense -
cashAccountidnullableThe bank account whose transactions the rule applies to, which must belong to the rule's mandate; when left out, the rule is not tied to a bank account.
-
amountobjectThe condition on the transaction's amount.
2 properties
-
valueintegerrequiredThe amount that the transaction's amount is compared against.
-
comparatorstringrequiredHow the transaction's amount is compared with
value.equalslessThanlessEqualgreaterThangreaterEqual
-
-
purposeobjectThe condition on the transaction's purpose.
-
counterpartNameobjectThe condition on the name of the transaction's counterpart.
-
counterpartAccountobjectThe condition on the account of the transaction's counterpart.
-
-
positionsobject[]requiredThe positions the rule books for a matching transaction, which replace the rule's current positions.
7 properties
-
accountintegerrequiredThe number of the counter account in the accounting plan, which must exist and be bookable; with the
postingReceiptoutcome it must be a cash, debtor or creditor account, or else a revenue account forrevenuerules or an expense account forexpenserules, and with thedonationProposaloutcome it must be an account that donations can use.1–999999999
-
taxCodestringrequirednullableThe code of a tax from the accounting plan, which is refused when the cost center region of
costCenter1has no taxes.1–5 characters
-
taxRatenumbernullableThe tax rate to apply, which is required when the tax of
taxCodehas no fixed rate and must be left out when that tax has a fixed rate or when notaxCodeis given.at most 99
-
costCenter1numberrequirednullableThe number of the first cost center, which must exist and be bookable; it is required when the accounting plan uses cost center regions, and then its first digit must be the digit of one of those regions.
1–99999999
-
costCenter2numberrequirednullableThe number of the second cost center, which must exist and be bookable.
1–99999999
-
dimensionsobject[]requiredThe dimension options chosen for the position, which may name each dimension only once and must include every active required dimension; with the
donationProposaloutcome, only dimensions that support donations apply.2 properties
-
dimensionIdidrequiredThe dimension that is chosen, which must be active.
-
optionKeystringrequiredThe key of the chosen option, which must be an active option of that dimension.
1–64 characters
-
-
sharenumberrequired0–100
-
curl --fail-with-body --silent --show-error --max-time 30 --globoff \
--request POST 'https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/YOUR_MANDATE_ID/finance/cash/transactions/rules/YOUR_CASH_TRANSACTION_RULE_ID/update' \
--header 'X-API-Key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Spenden Eingang Bank",
"matcher": {
"typeMatch": "revenue",
"cashAccount": null,
"purpose": {
"value": "Spende",
"comparator": "equals"
}
},
"outcome": "postingReceipt",
"positions": [
{
"account": 4000,
"taxCode": null,
"taxRate": null,
"costCenter1": null,
"costCenter2": null,
"dimensions": [
{
"dimensionId": "6b1353f9968718835b2ce0d0",
"optionKey": "general"
}
],
"share": 100
}
]
}'const response = await fetch("https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/YOUR_MANDATE_ID/finance/cash/transactions/rules/YOUR_CASH_TRANSACTION_RULE_ID/update", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
"name": "Spenden Eingang Bank",
"matcher": {
"typeMatch": "revenue",
"cashAccount": null,
"purpose": {
"value": "Spende",
"comparator": "equals"
}
},
"outcome": "postingReceipt",
"positions": [
{
"account": 4000,
"taxCode": null,
"taxRate": null,
"costCenter1": null,
"costCenter2": null,
"dimensions": [
{
"dimensionId": "6b1353f9968718835b2ce0d0",
"optionKey": "general"
}
],
"share": 100
}
]
}),
redirect: 'error',
signal: AbortSignal.timeout(30_000),
});
if (!response.ok) throw new Error(`campai HTTP ${response.status}`);
const text = await response.text();
const result = text ? JSON.parse(text) : null;
console.log(JSON.stringify(result, null, 2));<?php
$body = [
'name' => 'Spenden Eingang Bank',
'matcher' => [
'typeMatch' => 'revenue',
'cashAccount' => null,
'purpose' => [
'value' => 'Spende',
'comparator' => 'equals',
],
],
'outcome' => 'postingReceipt',
'positions' => [
[
'account' => 4000,
'taxCode' => null,
'taxRate' => null,
'costCenter1' => null,
'costCenter2' => null,
'dimensions' => [
[
'dimensionId' => '6b1353f9968718835b2ce0d0',
'optionKey' => 'general',
],
],
'share' => 100,
],
],
];
$context = stream_context_create(['http' => [
'method' => 'POST',
'header' => [
'X-API-Key: YOUR_API_KEY',
'Content-Type: application/json',
],
'content' => json_encode($body, JSON_THROW_ON_ERROR),
'timeout' => 30,
'follow_location' => 0,
'ignore_errors' => true,
]]);
$text = @file_get_contents('https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/YOUR_MANDATE_ID/finance/cash/transactions/rules/YOUR_CASH_TRANSACTION_RULE_ID/update', false, $context);
preg_match('/^HTTP\/\S+ (\d{3})/', $http_response_header[0] ?? '', $match);
$status = (int) ($match[1] ?? 0);
if ($text === false || $status < 200 || $status >= 300) {
throw new RuntimeException("campai HTTP $status (0 means no response)");
}
$result = $text === '' ? null : json_decode($text, true, 512, JSON_THROW_ON_ERROR);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR), PHP_EOL;
A request the admin app sent for “Edit a booking rule”.
Response
200 Successful response
No response body is specified.
What else happens
- The rule's
name,matcher,positionsandoutcomeare replaced with the values sent. Proposals the rule already made are not changed.
Errors
Caused by the request
| Status | Error | When |
|---|---|---|
| 400 | The bank account was not found or does not belong to this mandate | If matcher.cashAccount is set and that bank account does not exist or does not belong to the rule's mandate. |
| 400 | At least one matching condition must be set | If no matching condition is set in matcher. |
| 400 | Dimensions are not available for this product | If a position selects dimensions, which this product does not offer. Only region eu |
| 400 | A dimension can only be selected once | If a position selects the same dimension more than once. Only region us |
| 400 | The selected dimension or option is inactive or does not belong to this organization | If a position selects a dimension or option that is inactive or does not belong to the organization. For a donationProposal outcome, a dimension that does not apply to donations also counts as invalid. Only region us |
| 400 | A tax rate requires a tax code | If a position has a taxRate but no taxCode. |
| 400 | Invalid tax code "tax code" | If a position's taxCode is not in the accounting plan. |
| 400 | The tax code "tax code" has a fixed rate and does not accept a tax rate | If a position gives a taxRate for a tax code that has a fixed rate. |
| 400 | The tax code "tax code" requires a tax rate | If a position leaves out taxRate for a tax code that has no fixed rate. |
| 400 | Invalid tax rate "tax rate" | If a position's taxRate is not a valid tax rate. |
| 400 | Cost centers are not available for this product | If a position sets costCenter1 or costCenter2, which this product does not offer. Only region us |
| 400 | Regions in use so Cost-center 1 is required | If the accounting plan uses regions and a position has no costCenter1. Only region eu |
| 400 | The Cost-center 1 first digit has to be within "regions digits" | If the accounting plan uses regions and the first digit of a position's costCenter1 matches none of them. Only region eu |
| 400 | The chosen region cost center region disallows taxes | If a position has a taxCode but the region of its costCenter1 does not allow taxes. Only region eu |
| 400 | account name account number is invalid | If a position's account is not a valid account in the accounting plan. |
| 400 | account name account number is not bookable | If a position's account is not bookable. |
| 400 | The account is not a valid revenue account | If outcome is postingReceipt, the matcher's typeMatch is revenue, and a position's account is not a revenue, cash, debtor or creditor account. |
| 400 | The account is not a valid expense account | If outcome is postingReceipt, the matcher's typeMatch is expense, and a position's account is not an expense, cash, debtor or creditor account. |
| 400 | The account is not valid for donations | If outcome is donationProposal and a position's account cannot be used for donations. |
| 400 | A value is required for dimension "dimension" | If a position does not select a value for an active dimension that the organization marks as required. For a donationProposal outcome, only dimensions that apply to donations count. Only region us |
| 404 | Cash transaction rule not found | If the cash transaction rule does not exist in the mandate. |
Marked words such as tax code are filled in with the actual value when the error happens.
Caused by the organization's data
| Status | Error | When |
|---|---|---|
| 404 | A mandate needs to be provided | If the rule is not assigned to a mandate. |
| 404 | Accounting plan is missing. Please make sure you have setup your finances app properly. | If the organization has not set up its accounting plan. |
1 rare error, such as when something changes at the same moment
| Status | Error | When |
|---|---|---|
| 404 | Mandate mandate ID not found | If the rule's mandate can no longer be found. |
Marked words such as mandate ID are filled in with the actual value when the error happens.
Errors nearly every request can meet are listed under Errors.