Donation · Campaigns
Create donation campaign
Creates a donation campaign for a mandate using the supplied campaign details and optional cost centers. The cost centers are used for postings of booked donations to the campaign. Returns the new campaign’s _id.
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 organization access.
- The caller needs
mandate.readanddonationsSettings.editpermissions.
Request
Path parameters
-
organizationIdidrequired -
mandateIdidrequired
Body
Content-Type: application/json
-
namestringrequired1–100 characters
-
descriptionstringrequiredat most 1000 characters
-
availablebooleanrequired -
goalintegerrequirednullableat most 9999999999
-
costCenter1numberrequirednullable1–99999999
-
costCenter2numberrequirednullable1–99999999
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/donation/campaigns/createCampaign' \
--header 'X-API-Key: YOUR_API_KEY'const response = await fetch("https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/YOUR_MANDATE_ID/donation/campaigns/createCampaign", {
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/donation/campaigns/createCampaign', 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
-
_idid
Response200
{
"_id": "000000000000000000000001"
}
What else happens
- Creates a record in
donationCampaigns.
Errors
Other errors
| Status | Error | When |
|---|---|---|
| 400 | Cost centers are not available for this product | If a cost center is provided for a product that does not support cost centers, the endpoint returns 400 BAD_REQUEST with key finance.accounting.validateGetCostCenters.notSupportedByProduct. Only region us |
| 400 | The Cost-center 1 first digit has to be within "regions digits" | If regions are in use and the first digit of costCenter1 does not match a region, the endpoint returns 400 BAD_REQUEST with key finance.accounting.validateGetCostCenters.costCenter1Digits. Only region eu |
| 400 | cost center name "cost center number" is invalid | If a cost center being validated is not found, the endpoint returns 400 BAD_REQUEST with key finance.accounting.validateGetCostCenters.invalidCostCenter. costCenter1 may instead be just a region digit. Only region eu |
| 400 | cost center name "cost center number" is not bookable | If a cost center being validated is not bookable, the endpoint returns 400 BAD_REQUEST with key finance.accounting.validateGetCostCenters.notBookableCostCenter. Only region eu |
| 404 | A mandate needs to be provided | If the mandate ID is a null object ID, the endpoint returns 404 NOT_FOUND with key organization.getMandate.nullMandateId. |
| 404 | Mandate mandate ID not found | If the mandate is not found in the organization, the endpoint returns 404 NOT_FOUND with key organization.getMandate.notFound. |
| 404 | Accounting plan is missing. Please make sure you have setup your finances app properly. | If costCenter1 is provided but the accounting plan is missing, the endpoint returns 404 NOT_FOUND with key finance.accounting.getAccountingPlan.notFound. |
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.