Publish and Revert Post Drafts
Learn how to publish draft posts and revert published posts to drafts.
Overview
When we create a blog post, it is saved as a draft post by default. Draft posts are not visible to public users. We need to publish draft posts to make them publicly available. Similarly, we can take down the publicly available posts and revert them to drafts.
Methods
In this lesson, we'll learn how to publish an already created draft post so that it is publicly available. We'll also learn how to revert a published post to a draft state to revoke its public access.
Publish a draft post
We can publish a draft post by making a POST
request to the following URL:
https://blogger.googleapis.com/v3/blogs/{blogId}/posts/{postId}/publish
This endpoint requires the blogId
of the blog that contains the post that we would like to publish, as well as the postId
of the post itself.
Request Parameters
Request Parameters
Parameter | Type | Category | Description |
| string | required | The ID of the post's blog. |
| string | required | The ID of the post to be published. |
| datetime | optional | The date and time at which to publish the post. |
Sample code
In the code below, enter the values for the required parameters blogId
and postId
on lines 1–2. You can also schedule the post for publishing on a given date and time by specifying the value for the optional parameter publishDate
.
Click the "Run" button to see the output.
blogId = ''postId = ''url = 'https://blogger.googleapis.com/v3/blogs/' \+ blogId + '/posts/' + postId + '/publish'response = requests.post(url, headers=headers)printResponse(response)
The above code displays the published post object that contains the attributes listed in the post properties table in the previous lesson. An appropriate error message will be displayed if the API call fails.
Revert a post to draft state
Similarly, we can revert a published post to a draft state by making a POST
request to the following URL:
https://blogger.googleapis.com/v3/blogs/{blogId}/posts/{postId}/revert
This endpoint requires the blogId
of the blog that contains the post that we would like to revert, as well as the postId
of the post itself.
Request Parameters
Parameter | Type | Category | Description |
| string | required | The ID of the post's blog. |
| string | required | The ID of the post to be reverted. |
Sample code
In the code below, enter the values for the required parameters blogId
and postId
on lines 1–2.
Click the "Run" button to see the output.
blogId = ''postId = ''url = 'https://blogger.googleapis.com/v3/blogs/' \+ blogId + '/posts/' + postId + '/revert'response = requests.post(url, headers=headers)printResponse(response)
The above code displays the specified post object that contains the attributes listed in the post properties table in the previous lesson. An appropriate error message will be displayed if the API call fails.