Crm · Social posts
Refresh post statistics
Requests a refresh of a social post’s statistics for one account. It takes organizationId, postId, and accountId, and returns postId. The account’s figures may also be refreshed.
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 and the
social.editpermission.
Request
Path parameters
-
organizationIdidrequired -
postIdidrequired -
accountIdidrequired
Request
curl --fail-with-body --silent --show-error --max-time 30 --globoff \
--request POST 'https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/crm/communication/socialPosts/YOUR_POST_ID/deliveries/YOUR_ACCOUNT_ID/statistics/refresh' \
--header 'X-API-Key: YOUR_API_KEY'const response = await fetch("https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/crm/communication/socialPosts/YOUR_POST_ID/deliveries/YOUR_ACCOUNT_ID/statistics/refresh", {
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/crm/communication/socialPosts/YOUR_POST_ID/deliveries/YOUR_ACCOUNT_ID/statistics/refresh', 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;
Response
200 Successful response
Content-Type: application/json
-
postIdid
Response200
{
"postId": "000000000000000000000001"
}
What else happens
- When the statistics are refreshable, the endpoint sets
nextFetchAtto the current time on thesocialPostMetricsrecord. - The endpoint submits
crm.refreshSocialPostMetricstoDefaultQueueafter saving the refresh request. A queue submission failure is caught. - If the latest account metrics have no update time or were updated at least 15 minutes ago, the endpoint submits
crm.refreshSocialAccountMetricstoDefaultQueue. A queue submission failure is caught.
Errors
Other errors
| Status | Error | When |
|---|---|---|
| 409 | Connect the channel again to refresh its statistics. | If the account is missing or not connected, the endpoint returns HTTP 409 CONFLICT with key socialPost.statisticsAccountNotConnected. |
| 409 | The statistics of this publication cannot be refreshed now. They can be refreshed once every 15 minutes. | If the account is connected but statistics are missing, have no refresh time, or are not yet refreshable, the endpoint returns HTTP 409 CONFLICT with key socialPost.statisticsNotRefreshable. |
Errors nearly every request can meet are listed under Errors.