Search.../

getDraftPost( )

Gets a draft post by the provided ID.

Description

Uses the provided draftPostId to retrieve a draft post.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Authorization

Request

This endpoint does not take any parameters

Response Object

NAME
TYPE
DESCRIPTION
draftPost
DraftPost

Draft post info.

Status/Error Codes

Was this helpful?

Get 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: "d655251a-74eb-467d-9beb-1962984b8d94"
6
7const elevatedGetDraftPost = elevate(draftPosts.getDraftPost);
8
9export const myGetDraftPostFunction = webMethod(
10 Permissions.Admin,
11 async (draftPostId) => {
12 try {
13 const draftPost = await elevatedGetDraftPost(draftPostId);
14 console.log('Successfully retrieved the following draft post:', draftPost);
15 return draftPost;
16 } catch (error) {
17 console.error(error);
18 // Handle the error
19 }
20 }
21);
22
23/* Promise resolves to:
24 * {
25 * "_id": "d655251a-74eb-467d-9beb-1962984b8d94",
26 * "_createdDate": "2023-12-20T16:45:50.910Z",
27 * "categoryIds": [
28 * "c8780752-f517-4cf9-9c18-0f9a22d00926",
29 * "590635d7-cc7c-48cb-970c-f8339daa1cfe",
30 * "2b2ccb5a-e709-45a1-8353-bb3332b91297",
31 * "f2975644-ebb7-475f-baf5-5eb2b195880b"
32 * ],
33 * "changeOrigin": "MANUAL_SAVE",
34 * "commentingEnabled": true,
35 * "contentId": "65a639b469a6e0d73c4adfa6",
36 * "editedDate": "2024-01-16T08:09:50.581Z",
37 * "editingSessionId": "c8ce3dff-5005-4d40-badf-ceece77bc658",
38 * "featured": false,
39 * "hashtags": [],
40 * "hasUnpublishedChanges": true,
41 * "language": "en",
42 * "media": {
43 * "custom": false,
44 * "displayed": true,
45 * "wixMedia": {
46 * "image": "wix:image://v1/wixsite_524366693776674a6a5559~mv2_d_6000_4000_s_4_2.jpg/orange%20tabby%20kitten%20in%20grasses.jpg#originWidth=6000&originHeight=4000"
47 * }
48 * },
49 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
50 * "minutesToRead": 2,
51 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
52 * "pricingPlanIds": [],
53 * "relatedPostIds": [],
54 * "seoData": {
55 * "settings": {
56 * "keywords": [],
57 * "preventAutoRedirect": false
58 * },
59 * "tags": []
60 * },
61 * "seoSlug": "living-from-redemption",
62 * "slugs": [],
63 * "status": "UNPUBLISHED",
64 * "tagIds": [
65 * "6d2e0a31-0f5e-4de8-8fd7-e45352bdfa67",
66 * "a55b2c06-cbec-4d01-a8bb-cd7029056c75",
67 * "d2b0c02b-72c1-45af-ba58-3520cec9abe3"
68 * ],
69 * "title": "The task at hand is worth it!",
70 * "translations": []
71 * }
72 */
73
Get a draft post using options (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/*
6 * Sample draftPostId value: "57194b39-c4bc-45a6-a30d-f8e860a020b2"
7 *
8 * Sample options value:
9 * {
10 * fieldsets: ["GENERATED_EXCERPT"]
11 * }
12 */
13
14const elevatedGetDraftPost = elevate(draftPosts.getDraftPost);
15
16export const myGetDraftPostFunction = webMethod(
17 Permissions.Admin,
18 async (draftPostId, options) => {
19 try {
20 const draftPost = await elevatedGetDraftPost(draftPostId, options);
21 console.log('Successfully retrieved the following draft post:', draftPost);
22 return draftPost;
23 } catch (error) {
24 console.error(error);
25 // Handle the error
26 }
27 }
28);
29
30/* Promise resolves to:
31 * {
32 * "_id": "57194b39-c4bc-45a6-a30d-f8e860a020b2",
33 * "_createdDate": "2024-01-10T20:46:38.739Z",
34 * "categoryIds": [
35 * "c8780752-f517-4cf9-9c18-0f9a22d00926",
36 * "590635d7-cc7c-48cb-970c-f8339daa1cfe",
37 * "2b2ccb5a-e709-45a1-8353-bb3332b91297",
38 * "f2975644-ebb7-475f-baf5-5eb2b195880b"
39 * ],
40 * "changeOrigin": "MANUAL_SAVE",
41 * "commentingEnabled": true,
42 * "contentId": "65a639fd69a6e0d73c4adfad",
43 * "editedDate": "2024-01-16T08:11:09.845Z",
44 * "editingSessionId": "2e890d37-1a69-4153-9cc0-a36ea7e3d4ea",
45 * "excerpt": "No-one can understand the height of it. It required everything from me.",
46 * "featured": false,
47 * "hashtags": [],
48 * "hasUnpublishedChanges": true,
49 * "language": "en",
50 * "media": {
51 * "custom": false,
52 * "displayed": true,
53 * "wixMedia": {
54 * "image": "wix:image://v1/nsplsh_c9fb970af95242248fef3697783cd3db~mv2.jpg/Sunset%20on%20Monterosa.jpg#originWidth=3840&originHeight=5760"
55 * }
56 * },
57 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
58 * "minutesToRead": 7,
59 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
60 * "pricingPlanIds": [],
61 * "relatedPostIds": [],
62 * "seoData": {
63 * "settings": {
64 * "keywords": [],
65 * "preventAutoRedirect": false
66 * },
67 * "tags": []
68 * },
69 * "slugs": [],
70 * "status": "UNPUBLISHED",
71 * "tagIds": [
72 * "6d2e0a31-0f5e-4de8-8fd7-e45352bdfa67",
73 * "a55b2c06-cbec-4d01-a8bb-cd7029056c75",
74 * "d2b0c02b-72c1-45af-ba58-3520cec9abe3",
75 * "27f5320b-d91f-4435-9b9b-4b1d41b2ae70"
76 * ],
77 * "title": "Mountain Ranger",
78 * "translations": [],
79 * "url": "https://angeliquefm.wixsite.com/delicious-monster/post/mountain-ranger"
80 * }
81 */
Get a draft post (dashboard page example)

Copy Code
1import { draftPosts } from 'wix-blog-backend';
2
3// Sample draftPostId value: "d655251a-74eb-467d-9beb-1962984b8d94"
4
5export async function myGetDraftPostFunction(draftPostId) {
6 try {
7 const draftPost = await draftPosts.getDraftPost(draftPostId);
8 console.log('Successfully retrieved the following draft post:', draftPost);
9 return draftPost;
10 } catch (error) {
11 console.error(error);
12 // Handle the error
13 }
14 }
15
16/* Promise resolves to:
17 * {
18 * "_id": "d655251a-74eb-467d-9beb-1962984b8d94",
19 * "_createdDate": "2023-12-20T16:45:50.910Z",
20 * "categoryIds": [
21 * "c8780752-f517-4cf9-9c18-0f9a22d00926",
22 * "590635d7-cc7c-48cb-970c-f8339daa1cfe",
23 * "2b2ccb5a-e709-45a1-8353-bb3332b91297",
24 * "f2975644-ebb7-475f-baf5-5eb2b195880b"
25 * ],
26 * "changeOrigin": "MANUAL_SAVE",
27 * "commentingEnabled": true,
28 * "contentId": "65a639b469a6e0d73c4adfa6",
29 * "editedDate": "2024-01-16T08:09:50.581Z",
30 * "editingSessionId": "c8ce3dff-5005-4d40-badf-ceece77bc658",
31 * "featured": false,
32 * "hashtags": [],
33 * "hasUnpublishedChanges": true,
34 * "language": "en",
35 * "media": {
36 * "custom": false,
37 * "displayed": true,
38 * "wixMedia": {
39 * "image": "wix:image://v1/wixsite_524366693776674a6a5559~mv2_d_6000_4000_s_4_2.jpg/orange%20tabby%20kitten%20in%20grasses.jpg#originWidth=6000&originHeight=4000"
40 * }
41 * },
42 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
43 * "minutesToRead": 2,
44 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
45 * "pricingPlanIds": [],
46 * "relatedPostIds": [],
47 * "seoData": {
48 * "settings": {
49 * "keywords": [],
50 * "preventAutoRedirect": false
51 * },
52 * "tags": []
53 * },
54 * "seoSlug": "living-from-redemption",
55 * "slugs": [],
56 * "status": "UNPUBLISHED",
57 * "tagIds": [
58 * "6d2e0a31-0f5e-4de8-8fd7-e45352bdfa67",
59 * "a55b2c06-cbec-4d01-a8bb-cd7029056c75",
60 * "d2b0c02b-72c1-45af-ba58-3520cec9abe3"
61 * ],
62 * "title": "The task at hand is worth it!",
63 * "translations": []
64 * }
65 */
66