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';
4
5// Sample draftPostId value = "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b"
6
7const elevatedPublishDraftPost = elevate(draftPosts.publishDraftPost);
8
9export 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 error
19 }
20 }
21);
22
23/* 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';
2
3// Sample draftPostId value = "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b"
4
5export 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 error
13 }
14 }
15
16/* Promise resolves to:
17* {
18* "postId": "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b"
19* }
20*/