Restores a deleted draft post from the trash bin by the provided ID.
Uses the draftPostId
to restore a deleted draft post from the trash bin.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function restoreFromTrashBin(
draftPostId: string,
): Promise<RestoreFromTrashBinResponse>;
Draft post ID.
import { draftPosts } from "wix-blog-backend";
import { webMethod, Permissions } from "wix-web-module";
// Sample draftPostId value: "a128796d-6df0-4dae-9d4b-f0fc3441f42d"
export const myRestoreFromTrashBinFunction = webMethod(
Permissions.Admin,
async (draftPostId) => {
try {
const restoredDraftPost =
await draftPosts.restoreFromTrashBin(draftPostId);
console.log(
"Successfully restored the following draft post:",
restoredDraftPost,
);
return restoredDraftPost;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
/* Promise resolves to:
* {
* "draftPost": {
* "_id": "a128796d-6df0-4dae-9d4b-f0fc3441f42d",
* "_createdDate": "2024-01-09T11:43:30.710Z",
* "categoryIds": [
* "c8780752-f517-4cf9-9c18-0f9a22d00926",
* "2b2ccb5a-e709-45a1-8353-bb3332b91297"
* ],
* "changeOrigin": "RESTORE",
* "commentingEnabled": true,
* "contentId": "65a6449869a6e0d73c4ae0dd",
* "coverMedia": {
* "custom": false,
* "displayed": true,
* "enabled": true,
* "image": "wix:image://image.jpg#originWidth=3000&originHeight=2000"
* },
* "editedDate": "2024-01-16T08:55:52.829Z",
* "editingSessionId": "87f1a172-1632-42ec-bccd-1c22a54ca219",
* "featured": true,
* "hashtags": [],
* "hasUnpublishedChanges": true,
* "language": "en",
* "media": {
* "custom": false,
* "displayed": true,
* "wixMedia": {
* "image": "wix:image://image.jpg#originWidth=3000&originHeight=2000"
* }
* },
* "memberId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
* "minutesToRead": 0,
* "mostRecentContributorId": "c00e8a5c-322b-4e77-8813-002e3ea7e811",
* "pricingPlanIds": [],
* "relatedPostIds": [],
* "seoData": {
* "settings": {
* "keywords": [],
* "preventAutoRedirect": false
* },
* "tags": []
* },
* "slugs": [],
* "status": "UNPUBLISHED",
* "tagIds": [
* "27f5320b-d91f-4435-9b9b-4b1d41b2ae70",
* "6d2e0a31-0f5e-4de8-8fd7-e45352bdfa67"
* ],
* "title": "Genius Ways",
* "translations": []
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.