publishDraftPost( )


Publishes a specified draft post by ID. This creates a new post entity with the data from the draft post.

If the specified draft post was already published, the published post will be updated with the latest values from the draft post entity.

Authentication

This function requires elevated permissions and runs only on the backend and on dashboard pages.

Permissions
Manage Blog
Learn more about app permissions.
Method Declaration
Copy
function publishDraftPost(
  draftPostId: string,
): Promise<PublishDraftPostResponse>;
Method Parameters
draftPostIdstringRequired

Draft post ID.

Returns
Return Type:Promise<PublishDraftPostResponse>
JavaScript
import { draftPosts } from "wix-blog-backend"; import { webMethod, Permissions } from "wix-web-module"; import { elevate } from "wix-auth"; // Sample draftPostId value = "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b" const elevatedPublishDraftPost = elevate(draftPosts.publishDraftPost); export const myPublishDraftPostFunction = webMethod( Permissions.Admin, async (draftPostId) => { try { const publishedPost = await elevatedPublishDraftPost(draftPostId); console.log("Successfully published the following post:", publishedPost); return draftPostId; } catch (error) { console.error(error); // Handle the error } }, ); /* Promise resolves to: * { * "postId": "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b" * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?