Finance · Accounting · Budgets
Create budget
Creates a draft budget for a mandate and fiscal year and returns its budgetId. Choose empty, previousActuals, or previousBudget as the source. You can adjust amounts by a percentage and, for previous actuals, request a split by cost center.
Permissions
Send an API key of the organization in the path, using the X-API-Key header.
Who may call it
- The caller must have access to the organization.
- The caller needs
mandate.readandbudget.insertpermissions.
Request
Path parameters
-
organizationIdidrequired -
mandateIdidrequired
Body
Content-Type: application/json
-
fiscalYearintegerrequired2000–3000
-
sourcestringrequiredemptypreviousActualspreviousBudget -
adjustmentPercentnumber-100–1000 · default
0 -
splitByCostCenterbooleandefault
false
Request
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/accounting/budgets' \
--header 'X-API-Key: YOUR_API_KEY'const response = await fetch("https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/YOUR_MANDATE_ID/finance/accounting/budgets", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY"
},
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
$context = stream_context_create(['http' => [
'method' => 'POST',
'header' => [
'X-API-Key: YOUR_API_KEY',
],
'timeout' => 30,
'follow_location' => 0,
'ignore_errors' => true,
]]);
$text = @file_get_contents('https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/YOUR_MANDATE_ID/finance/accounting/budgets', 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;
No request that worked has been recorded yet, so the body is not shown.
Response
200 Successful response
Content-Type: application/json
-
budgetIdid
Response200
{
"budgetId": "000000000000000000000001"
}
What else happens
- The endpoint creates a budget record with status
draft.
Errors
Other errors
| Status | Error | When |
|---|---|---|
| 400 | There is no budget for the fiscal year before | If source is previousBudget and there is no budget for the previous fiscal year, the endpoint returns HTTP 400 with key routes.finance.accounting.budgets.noPreviousBudget. |
| 404 | Accounting plan is missing. Please make sure you have setup your finances app properly. | If the organization's accounting plan is missing, the endpoint returns HTTP 404 with key finance.accounting.getAccountingPlan.notFound. |
| 404 | Finances settings are missing | If the organization's finances settings are missing, the endpoint returns HTTP 404 with key finance.settings.getFinancesSettings.notFound. |
| 404 | A mandate needs to be provided | If no budget already exists and the mandate ID is the null object ID, the endpoint returns HTTP 404 with key organization.getMandate.nullMandateId. |
| 404 | Mandate mandate ID not found | If no budget already exists and the non-null mandate ID is not found in the organization, the endpoint returns HTTP 404 with key organization.getMandate.notFound. |
| 409 | This mandate already has a budget for this fiscal year | If the mandate already has a budget for the fiscal year, the endpoint returns HTTP 409 with key routes.finance.accounting.budgets.alreadyExists. |
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.