Create Draft Post
Draft posts can be created using the createPost mutation with the saveToDraft argument set to true. When saving a post as a draft, there are several required arguments:
The channel ID that the post is being created for
The scheduling type to be used for the post (automatic or notification)
The sharing mode to be used for the post (add the post to the queue, share it now or share it next)
The content to be used when creating the Post
The
saveToDraftflag set totrueto save the post as a draft instead of scheduling it
When a post is saved as a draft, the post status will be set to 'draft' instead of 'scheduled' and the post will not be published until explicitly scheduled.
When performing the mutation, the PostActionSuccess type can be used to retrieve the information for the Post that was created. Similarly, the MutationError will provide you with information on the error that was triggered when trying to create the post.
mutation CreateDraftPost {
createPost(input: {
text: "Hello there, this is a draft post!",
channelId: "some_channel_id",
schedulingType: automatic,
mode: addToQueue,
saveToDraft: true
}) {
... on PostActionSuccess {
post {
id
text
}
}
... on MutationError {
message
}
}
}
curl -X POST 'https://api.buffer.com' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{"query": "mutation CreateDraftPost {\n createPost(input: {\n text: \"Hello there, this is a draft post!\",\n channelId: \"some_channel_id\",\n schedulingType: automatic,\n mode: addToQueue,\n saveToDraft: true\n }) {\n ... on PostActionSuccess {\n post {\n id\n text\n }\n }\n ... on MutationError {\n message\n }\n }\n}"}'
const response = await fetch('https://api.buffer.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY',
},
body: JSON.stringify({
query: `
mutation CreateDraftPost {
createPost(input: {
text: "Hello there, this is a draft post!",
channelId: "some_channel_id",
schedulingType: automatic,
mode: addToQueue,
saveToDraft: true
}) {
... on PostActionSuccess {
post {
id
text
}
}
... on MutationError {
message
}
}
}
`,
}),
});
const data = await response.json();
console.log(data);
<?php
$query = '
mutation CreateDraftPost {
createPost(input: {
text: "Hello there, this is a draft post!",
channelId: "some_channel_id",
schedulingType: automatic,
mode: addToQueue,
saveToDraft: true
}) {
... on PostActionSuccess {
post {
id
text
}
}
... on MutationError {
message
}
}
}
';
$payload = [
'query' => $query,
];
$ch = curl_init('https://api.buffer.com');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer YOUR_API_KEY',
],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);