Search...
publishDraftPost( )
Publishes a specified draft post by ID. This creates a new post entity with the data from the draft post.
Description
If the specified draft post was already published, the published post will be updated with the latest values from the draft post entity.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function publishDraftPost(draftPostId: string): Promise<PublishDraftPostResponse>
publishDraftPost Parameters
NAME
TYPE
DESCRIPTION
draftPostId
string
Draft post ID.
Returns
Return Type:
Promise<
PublishDraftPostResponse
>NAME
TYPE
DESCRIPTION
postId
string
Published post ID.
Was this helpful?
Publish a draft post (export from backend code)
Copy Code
1import { draftPosts } from 'wix-blog-backend';2import { webMethod, Permissions } from 'wix-web-module';3import { elevate } from 'wix-auth';45// Sample draftPostId value = "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b"67const elevatedPublishDraftPost = elevate(draftPosts.publishDraftPost);89export const myPublishDraftPostFunction = webMethod(10 Permissions.Admin,11 async (draftPostId) => {12 try {13 const publishedPost = await elevatedPublishDraftPost(draftPostId);14 console.log('Successfully published the following post:', publishedPost);15 return draftPostId;16 } catch (error) {17 console.error(error);18 // Handle the error19 }20 }21);2223/* Promise resolves to:24* {25* "postId": "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b"26* }27*/
Publish a draft post (dashboard page code)
Copy Code
1import { draftPosts } from 'wix-blog-backend';23// Sample draftPostId value = "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b"45export async function myPublishDraftPostFunction(draftPostId) {6 try {7 const publishedPost = await draftPosts.publishDraftPost(draftPostId);8 console.log('Successfully published the following post:', publishedPost);9 return draftPostId;10 } catch (error) {11 console.error(error);12 // Handle the error13 }14 }1516/* Promise resolves to:17* {18* "postId": "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b"19* }20*/