Crm · Social posts
Publish social post
Publishes or schedules a social post using its text, media, targets and optional postId. It can also edit a scheduled post or correct and republish failed accounts on a post that has started publishing. Returns the postId.
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. An existing post requires
social.edit; a new post requiressocial.insert.
Request
Path parameters
-
organizationIdidrequired
Body
Content-Type: application/json
-
postIdid -
scheduledAtstring · date-timerequirednullable -
textstringrequiredat most 63206 characters
-
mediaobject[]requiredat most 35 items
4 properties
-
fileIdstring · uuidpattern
^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$ -
resourcestringat least 1 characters
-
fileNamestringrequirednullableat most 128 characters
-
kindstringrequiredimagevideo
-
-
targetsobject[]required1–50 items
4 properties
-
accountIdidrequired -
textstringrequirednullableat most 63206 characters
-
mediaobject[]requirednullableat most 35 items
4 properties
-
fileIdstring · uuidpattern
^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$ -
resourcestringat least 1 characters
-
fileNamestringrequirednullableat most 128 characters
-
kindstringrequiredimagevideo
-
-
settingsobjectrequired8 properties
-
titlestringrequirednullableat most 500 characters
-
boardIdstringrequirednullableat most 200 characters
-
privacystringrequirednullableat most 100 characters
-
disableCommentbooleandefault
true -
disableDuetbooleandefault
true -
disableStitchbooleandefault
true -
brandContentbooleandefault
false -
brandOrganicbooleandefault
false
-
-
curl --fail-with-body --silent --show-error --max-time 30 --globoff \
--request POST 'https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/crm/communication/socialPosts/publish' \
--header 'X-API-Key: YOUR_API_KEY'const response = await fetch("https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/crm/communication/socialPosts/publish", {
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/publish', 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
-
postIdid
{
"postId": "000000000000000000000001"
}
What else happens
- Creates a new
socialPostsrecord when no existing post is supplied. - Updates the content and targets of an existing scheduled post.
- Updates the selected deliveries of a post being corrected.
- When a correction leaves no problems needing attention, matching post notifications are deleted.
- When unread notifications are cleared, their
userWatchCountersare updated. - For an immediate publication, the endpoint submits a
crm.processSocialPostjob toDefaultQueue. If submission fails, the saved publication can be recovered by the scheduler.
Errors
Other errors
| Status | Error | When |
|---|---|---|
| 400 | A post that has already started publishing cannot be rescheduled. Correct it and publish it again right away. | A correction to a post that has started publishing cannot be scheduled. The response is HTTP 400 with key socialPost.correctionNotScheduled. |
| 400 | Each account can only be selected once. | If an account is selected more than once, the response is HTTP 400 with key socialPost.duplicateAccounts. |
| 400 | These accounts are no longer connected: names. Reconnect them or remove them from the post. | If a selected account is not connected to the organization, the response is HTTP 400 with key socialPost.accountsUnavailable. |
| 400 | A file changed its type. Remove it and upload it again. | If the same file is specified with different kinds, or a reused file's kind differs from its stored kind, the response is HTTP 400 with key socialPost.mediaKindMismatch. |
| 400 | A post can contain at most count different files across all accounts. | If the post has too many different files across its accounts, the response is HTTP 400 with key socialPost.mediaTooMany. |
| 400 | The uploaded file “name” is no longer available. Add it again. | If a referenced file is no longer available, the response is HTTP 400 with key socialPost.mediaExpired. |
| 400 | The file “name” is empty, has the wrong type or is larger than 100 MB. | If a file is empty, has the wrong type or exceeds the size limit, the response is HTTP 400 with key socialPost.mediaInvalid. |
| 409 | This publication can no longer be retried or checked. Refresh its status. | If a correction targets a delivery that cannot be retried, including one that becomes non-retryable during the request, the response is HTTP 409 with key socialPost.deliveryNotRetryable. |
| 409 | This post is no longer scheduled. It may already be publishing. | If a post being edited is no longer scheduled, the response is HTTP 409 with key socialPost.notScheduled. |
Marked words such as names are filled in with the actual value when the error happens.
Errors nearly every request can meet are listed under Errors.