Search.../

listDraftPosts( )

Retrieves a list of up to 100 draft posts per request.

Description

List Draft Posts runs with these defaults, which you can override:

  • editedDate is sorted in descending order.
  • paging.limit is 50.
  • paging.offset is 0.
Admin Method

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

Syntax

function listDraftPosts(options: ListDraftPostsOptions): Promise<ListDraftPostsResponse>

listDraftPosts Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListDraftPostsOptions

Options for listing multiple draft posts.

Returns

Return Type:

Promise<
ListDraftPostsResponse
>
NAME
TYPE
DESCRIPTION
draftPosts
Array<
DraftPost
>

List of draft posts.

metaData
MetaData

Details on the paged set of results returned.

Was this helpful?

List draft posts (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
5const elevatedListDraftPost = elevate(draftPosts.listDraftPosts);
6
7export const myListDraftPostFunction = webMethod(
8 Permissions.Admin,
9 async () => {
10 try {
11 const draftPosts = await elevatedListDraftPost();
12 console.log('Successfully retrieved the following draft posts:', draftPosts);
13 return draftPosts;
14 } catch (error) {
15 console.error(error);
16 // Handle the error
17 }
18 }
19);
20
21/* Promise resolves to:
22 * {
23 * "draftPosts": [
24 * {
25 * "_id": "57194b39-c4bc-45a6-a30d-f8e860a020b2",
26 * "_createdDate": "2024-01-10T20:46:38.739Z",
27 * "categoryIds": [],
28 * "changeOrigin": "MANUAL_SAVE",
29 * "commentingEnabled": true,
30 * "contentId": "659f0938ca4ad1a823a0fe29",
31 * "editingSessionId": "2e890d37-1a69-4153-9cc0-a36ea7e3d4ea",
32 * "editedDate": "2024-01-10T21:16:53.964Z",
33 * "featured": false,
34 * "hashtags": [],
35 * "hasUnpublishedChanges": true,
36 * "language": "en",
37 * "media": {
38 * "custom": false,
39 * "displayed": true,
40 * "wixMedia": {
41 * "image": "wix:image://v1/nsplsh_c9fb970af95242248fef3697783cd3db~mv2.jpg/Sunset%20on%20Monterosa.jpg#originWidth=3840&originHeight=5760"
42 * }
43 * },
44 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
45 * "minutesToRead": 7,
46 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
47 * "pricingPlanIds": [],
48 * "relatedPostIds": [],
49 * "seoData": {
50 * "settings": {
51 * "keywords": [],
52 * "preventAutoRedirect": false
53 * },
54 * "tags": []
55 * },
56 * "slugs": [],
57 * "status": "UNPUBLISHED",
58 * "tagIds": [],
59 * "title": "Mountain Ranger",
60 * "translations": []
61 * },
62 * {
63 * "_id": "d12f2ef2-c0f6-4913-b04f-aeeba2165b93",
64 * "_createdDate": "2024-01-09T11:46:42.933Z",
65 * "categoryIds": [],
66 * "changeOrigin": "PUBLISH",
67 * "commentingEnabled": true,
68 * "contentId": "659d322302ee7b202a1745de",
69 * "editingSessionId": "4e14aa41-ad7f-4e25-b4c4-df7144002aaf",
70 * "editedDate": "2024-01-09T11:46:42.933Z",
71 * "featured": true,
72 * "firstPublishedDate": "2024-01-09T11:46:43.034Z",
73 * "hashtags": [],
74 * "hasUnpublishedChanges": false,
75 * "language": "en",
76 * "media": {
77 * "custom": false,
78 * "displayed": true
79 * },
80 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
81 * "minutesToRead": 0,
82 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
83 * "pricingPlanIds": [],
84 * "relatedPostIds": [],
85 * "seoData": {
86 * "tags": []
87 * },
88 * "seoSlug": "rocket-man",
89 * "slugs": [
90 * "rocket-man"
91 * ],
92 * "status": "PUBLISHED",
93 * "tagIds": [],
94 * "title": "Rocket Man",
95 * "translations": []
96 * }
97 * ],
98 * "metaData": {
99 * "count": 2,
100 * "offset": 0,
101 * "total": 17
102 * }
103 * }
104 */
List draft posts 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/* Sample options value":
6 * {
7 * "fieldsets": ["URL"],
8 * "language": "en",
9 * "paging": {
10 * "cursor": "",
11 * "limit": 5,
12 * "offset": 0
13 * },
14 * "sort": "EDITING_DATE_DESC",
15 * "status": "PUBLISHED"
16 * }
17 */
18
19const elevatedListDraftPost = elevate(draftPosts.listDraftPosts);
20
21export const myListDraftPostFunction = webMethod(
22 Permissions.Admin,
23 async (options) => {
24 try {
25 const draftPosts = await elevatedListDraftPost(options);
26 console.log("Successfully retrieved the following draft posts":", draftPosts);
27 return draftPosts;
28 } catch (error) {
29 console.error(error);
30 // Handle the error
31 }
32 }
33);
34
35/* Promise resolves to":
36 * {
37 * "draftPosts": [
38 * {
39 * "_id": "50c86b02-e508-4426-8fcc-9538d05f4d46",
40 * "_createdDate": "2024-01-16T10":07":25.765Z",
41 * "categoryIds": [
42 * "590635d7-cc7c-48cb-970c-f8339daa1cfe",
43 * "f2975644-ebb7-475f-baf5-5eb2b195880b",
44 * "2b2ccb5a-e709-45a1-8353-bb3332b91297"
45 * ],
46 * "changeOrigin": "PUBLISH",
47 * "commentingEnabled": true,
48 * "contentId": "65ae303933529bcd93f5a715",
49 * "editedDate": "2024-01-22T09":07":05.418Z",
50 * "editingSessionId": "f0596aa9-95c8-4833-8f83-aa7ce2caa1e0",
51 * "excerpt": "When you don"t know what to do, you gotta ask yourself...",
52 * "featured": false,
53 * "firstPublishedDate": "2024-01-16T10":07":25.837Z",
54 * "hashtags": [],
55 * "hasUnpublishedChanges": false,
56 * "language": "en",
57 * "media": {
58 * "custom": false,
59 * "displayed": true
60 * },
61 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
62 * "minutesToRead": 0,
63 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
64 * "pricingPlanIds": [],
65 * "relatedPostIds": [
66 * "d655251a-74eb-467d-9beb-1962984b8d94",
67 * "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b",
68 * "f3b0fb3b-1a70-45d6-9a8f-cd885f0db48c"
69 * ],
70 * "seoData": {
71 * "settings": {
72 * "preventAutoRedirect": false,
73 * "keywords": []
74 * },
75 * "tags": []
76 * },
77 * "seoSlug": "american-pie",
78 * "slugs": [
79 * "american-pie"
80 * ],
81 * "status": "PUBLISHED",
82 * "tagIds": [],
83 * "title": "American Pie",
84 * "translations": [],
85 * "url": "https"://.wixsite.com/american-pie"
86 * },
87 * {
88 * "_id": "94t86b07-e508-4426-8fgg-9538d05y4d89",
89 * "_createdDate": "2024-01-16T10":07":25.765Z",
90 * "categoryIds": [
91 * "590635d7-cc7c-48cb-970c-f8339daa1cfe",
92 * "f2975644-ebb7-475f-baf5-5eb2b195880b",
93 * "2b2ccb5a-e709-45a1-8353-bb3332b91297"
94 * ],
95 * "changeOrigin": "PUBLISH",
96 * "commentingEnabled": true,
97 * "contentId": "95ge303933529bcd93f5a7837",
98 * "editedDate": "2024-01-22T09":07":05.418Z",
99 * "editingSessionId": "f0596aa9-95c8-4833-8f83-aa7ce2caa1e0",
100 * "excerpt": "Why do you think it is important?",
101 * "featured": true,
102 * "firstPublishedDate": "2024-01-16T10":07":25.837Z",
103 * "hashtags": [],
104 * "hasUnpublishedChanges": false,
105 * "language": "en",
106 * "media": {
107 * "custom": false,
108 * "displayed": true
109 * },
110 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
111 * "minutesToRead": 0,
112 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
113 * "pricingPlanIds": [],
114 * "relatedPostIds": [
115 * "d655251a-74eb-467d-9beb-1962984b8d94",
116 * "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b",
117 * "f3b0fb3b-1a70-45d6-9a8f-cd885f0db48c"
118 * ],
119 * "seoData": {
120 * "settings": {
121 * "preventAutoRedirect": false,
122 * "keywords": []
123 * },
124 * "tags": []
125 * },
126 * "seoSlug": "whatchawannado",
127 * "slugs": [
128 * "whatchawannado"
129 * ],
130 * "status": "PUBLISHED",
131 * "tagIds": [],
132 * "title": "Whatchawannado",
133 * "translations": [],
134 * "url": "https"://wixsite.com/post/whatchawannado"
135 * }
136 * ],
137 * "metaData": {
138 * "count": 2,
139 * "offset": 0,
140 * "total": 2
141 * }
142 *}
143 */
List draft posts (dashboard page code)

Copy Code
1import { draftPosts } from 'wix-blog-backend';
2
3export async function myListDraftPostFunction() {
4 try {
5 const posts = await draftPosts.listDraftPosts();
6 console.log('Successfully retrieved the following draft posts:', posts);
7 return draftPosts;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12 }
13
14/* Promise resolves to:
15 * {
16 * "draftPosts": [
17 * {
18 * "_id": "57194b39-c4bc-45a6-a30d-f8e860a020b2",
19 * "_createdDate": "2024-01-10T20:46:38.739Z",
20 * "categoryIds": [],
21 * "changeOrigin": "MANUAL_SAVE",
22 * "commentingEnabled": true,
23 * "contentId": "659f0938ca4ad1a823a0fe29",
24 * "editingSessionId": "2e890d37-1a69-4153-9cc0-a36ea7e3d4ea",
25 * "editedDate": "2024-01-10T21:16:53.964Z",
26 * "featured": false,
27 * "hashtags": [],
28 * "hasUnpublishedChanges": true,
29 * "language": "en",
30 * "media": {
31 * "custom": false,
32 * "displayed": true,
33 * "wixMedia": {
34 * "image": "wix:image://v1/nsplsh_c9fb970af95242248fef3697783cd3db~mv2.jpg/Sunset%20on%20Monterosa.jpg#originWidth=3840&originHeight=5760"
35 * }
36 * },
37 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
38 * "minutesToRead": 7,
39 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
40 * "pricingPlanIds": [],
41 * "relatedPostIds": [],
42 * "seoData": {
43 * "settings": {
44 * "keywords": [],
45 * "preventAutoRedirect": false
46 * },
47 * "tags": []
48 * },
49 * "slugs": [],
50 * "status": "UNPUBLISHED",
51 * "tagIds": [],
52 * "title": "Mountain Ranger",
53 * "translations": []
54 * },
55 * {
56 * "_id": "d12f2ef2-c0f6-4913-b04f-aeeba2165b93",
57 * "_createdDate": "2024-01-09T11:46:42.933Z",
58 * "categoryIds": [],
59 * "changeOrigin": "PUBLISH",
60 * "commentingEnabled": true,
61 * "contentId": "659d322302ee7b202a1745de",
62 * "editingSessionId": "4e14aa41-ad7f-4e25-b4c4-df7144002aaf",
63 * "editedDate": "2024-01-09T11:46:42.933Z",
64 * "featured": true,
65 * "firstPublishedDate": "2024-01-09T11:46:43.034Z",
66 * "hashtags": [],
67 * "hasUnpublishedChanges": false,
68 * "language": "en",
69 * "media": {
70 * "custom": false,
71 * "displayed": true
72 * },
73 * "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
74 * "minutesToRead": 0,
75 * "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
76 * "pricingPlanIds": [],
77 * "relatedPostIds": [],
78 * "seoData": {
79 * "tags": []
80 * },
81 * "seoSlug": "rocket-man",
82 * "slugs": [
83 * "rocket-man"
84 * ],
85 * "status": "PUBLISHED",
86 * "tagIds": [],
87 * "title": "Rocket Man",
88 * "translations": []
89 * }
90 * ],
91 * "metaData": {
92 * "count": 2,
93 * "offset": 0,
94 * "total": 17
95 * }
96 * }
97 */