Creates a draft post.
The draft post's memberId
is required for third-party apps.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createDraftPost(
draftPost: DraftPost,
options: CreateDraftPostOptions,
): Promise<CreateDraftPostResponse>;
Draft post to create.
Options for creating a draft post.
import { draftPosts } from 'wix-blog-backend';
import { webMethod, Permissions } from 'wix-web-module';
import { elevate } from 'wix-auth';
/* Sample draftPost value:
* {
* "categoryIds": [],
* "commentingEnabled": true,
* "excerpt": "Knowing nothing of the early movement, it was a chase in the dark.",
* "featured": true,
* "language": "en",
* "media": {
* "custom": false,
* "displayed": true
* },
* "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
* "previewTextParagraph": 2,
* "pricingPlanIds": [],
* "relatedPostIds": [],
* "richContent": {
* "nodes": [
* {
* "type": "PARAGRAPH",
* "id": "pvirv1",
* "nodes": [
* {
* "type": "TEXT",
* "id": "",
* "nodes": [],
* "textData": {
* "text": "Hello world",
* "decorations": []
* }
* }
* ],
* "paragraphData": {}
* }
* ],
* }
* "seoData": {
* "tags": []
* "},
* "seoSlug": "on-our-side-1",
* "tagIds": [],
* "title": "On our side.",
* }
*/
const elevatedCreateDraftPost = elevate(draftPosts.createDraftPost);
export const myCreateDraftPostFunction = webMethod(
Permissions.Admin,
async (draftPost) => {
try {
const createdDraftPost = await elevatedCreateDraftPost(draftPost);
console.log("Successfully created the following draft post":", createdDraftPost);
return createdDraftPost;
} catch (error) {
console.error(error);
// Handle the error
}
}
);
/* Promise resolves to:
* {
* "_id": "9bf5b0c2-3e06-499f-9c35-7e1b2ba91ae8",
* "_createdDate": "2024-01-23T10":53":19.658Z",
* "categoryIds": [],
* "changeOrigin": "MANUAL_SAVE",
* "commentingEnabled": true,
* "contentId": "65af9a9ff178881294652e92",
* "editedDate": "2024-01-23T10":53":19.658Z",
* "editingSessionId": "7e79aa62-c68a-4b24-b9be-ae07f5ada751",
* "excerpt": "Knowing nothing of the early movement, it was a chase in the dark.",
* "featured": true,
* "hashtags": [],
* "hasUnpublishedChanges": true,
* "language": "en",
* "media": {
* "custom": false,
* "displayed": true
* },
* "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
* "minutesToRead": 0,
* "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
* "paidContentParagraph": 2,
* "pricingPlanIds": [],
* "previewTextParagraph": 2,
* "relatedPostIds": [],
* "richContent": {
* "nodes": [
* {
* "type": "PARAGRAPH",
* "id": "pvirv1",
* "nodes": [
* {
* "type": "TEXT",
* "id": "",
* "nodes": [],
* "textData": {
* "text": "Hello world",
* "decorations": []
* }
* }
* ],
* "paragraphData": {}
* }
* ],
* }
* "seoData": {
* "settings": {
* "keywords": [],
* "preventAutoRedirect": false
* },
* "tags": []
* },
* "seoSlug": "on-our-side-1",
* "slugs": [],
* "status": "UNPUBLISHED",
* "tagIds": [],
* "title": "On our side.",
* "translations": []
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.