getDraftPost( )


Gets a draft post by the provided ID.

Uses the provided draftPostId to retrieve a draft post.

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 getDraftPost(
  draftPostId: string,
  options: GetDraftPostOptions,
): Promise<GetDraftPostResponse>;
Method Parameters
draftPostIdstringRequired

Draft post ID.


optionsGetDraftPostOptions

Options for getting a draft post.

Returns
Return Type:Promise<GetDraftPostResponse>
JavaScript
import { draftPosts } from "wix-blog-backend"; import { webMethod, Permissions } from "wix-web-module"; import { elevate } from "wix-auth"; // Sample draftPostId value: "d655251a-74eb-467d-9beb-1962984b8d94" const elevatedGetDraftPost = elevate(draftPosts.getDraftPost); export const myGetDraftPostFunction = webMethod( Permissions.Admin, async (draftPostId) => { try { const draftPost = await elevatedGetDraftPost(draftPostId); console.log( "Successfully retrieved the following draft post:", draftPost, ); return draftPost; } catch (error) { console.error(error); // Handle the error } }, ); /* Promise resolves to: * { * "_id": "d655251a-74eb-467d-9beb-1962984b8d94", * "_createdDate": "2023-12-20T16:45:50.910Z", * "categoryIds": [ * "c8780752-f517-4cf9-9c18-0f9a22d00926", * "590635d7-cc7c-48cb-970c-f8339daa1cfe", * "2b2ccb5a-e709-45a1-8353-bb3332b91297", * "f2975644-ebb7-475f-baf5-5eb2b195880b" * ], * "changeOrigin": "MANUAL_SAVE", * "commentingEnabled": true, * "contentId": "65a639b469a6e0d73c4adfa6", * "editedDate": "2024-01-16T08:09:50.581Z", * "editingSessionId": "c8ce3dff-5005-4d40-badf-ceece77bc658", * "featured": false, * "hashtags": [], * "hasUnpublishedChanges": true, * "language": "en", * "media": { * "custom": false, * "displayed": true, * "wixMedia": { * "image": "wix:image://v1/wixsite_524366693776674a6a5559~mv2_d_6000_4000_s_4_2.jpg/orange%20tabby%20kitten%20in%20grasses.jpg#originWidth=6000&originHeight=4000" * } * }, * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811", * "minutesToRead": 2, * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811", * "pricingPlanIds": [], * "relatedPostIds": [], * "seoData": { * "settings": { * "keywords": [], * "preventAutoRedirect": false * }, * "tags": [] * }, * "seoSlug": "living-from-redemption", * "slugs": [], * "status": "UNPUBLISHED", * "tagIds": [ * "6d2e0a31-0f5e-4de8-8fd7-e45352bdfa67", * "a55b2c06-cbec-4d01-a8bb-cd7029056c75", * "d2b0c02b-72c1-45af-ba58-3520cec9abe3" * ], * "title": "The task at hand is worth it!", * "translations": [] * } */
Errors

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

Did this help?