Create, Update, and Delete a Post
Learn about the blog post and how to create, update, and delete it.
Overview
A post, or a blog post, is an article that contains information written by an author on a certain topic. The content is published for public access. Sometimes the post is only meaningful for a limited number of users, and in some cases, for a limited duration of time. Sometimes the posts become obsolete, such as when the technology discussed in the post changes.
Post properties
The table below shows the complete list of properties that are part of the post class.
Parameter | Type | Description |
| string | The type of object. Value: "blogger#post" Note: This value is fixed. |
| string | The ID of the post. |
| object | The object that contains the post's blog data. |
| string | The ID of the post's blog. |
| datetime | The post's publishing date. Format: yyyy-mm-dd |
| datetime | The date of the post's last update. Format: yyyy-mm-dd |
| string | The published link of the post. |
| string | The Blogger API URL of the post. |
| string | The title of the post. |
| string | The content of the post. Note: This value can include HTML. |
| object | The object that contains the post's author information. |
| string | The ID of the post's author. |
| string | The name of the post's author. |
| string | The published link of the author profile. |
| object | The object that contains the author's avatar information. |
| string | The URL of the author avatar. |
| object | The object that contains the post's comments. |
| long | The number of comments on the post. |
| string | The Blogger API URL of the post's comments. |
| list | The list of tags associated with the post. |
| string | The metadata of the post. |
| list | The list of comments on the post. |
| object | The object that contains the location information of the post. Note: This value is only available if the post was geotagged. |
| string | The name of the post's location. |
| double | The latitude of the post's location. |
| double | The longitude of the post's location. |
| string | The viewport span of the post's location. |
| string | The URL of the title. |
| list | The post's display image. |
| string | The URL of the post's display image. |
| string | The status of the post. Note: This value is set only for admin-level requests. |
Methods
We'll now take a look at different methods of the post class to create, update, and delete a blog post.
Create a post
We can create a blog post by sending a POST
request to the following URL:
https://blogger.googleapis.com/v3/blogs/{blogId}/posts
This endpoint requires a post object that contains the attributes given in the table above as part of the request body. Moreover, it also requires the blogId
of the blog that we would like to add the new post to.
Request parameters
Parameter | Type | Category | Description |
| string | required | The ID of the blog to add the post to. |
| boolean | optional | "True" to create the post as a draft, "False" otherwise. |
Sample code
In the code below, enter the value for the required parameter blogId
on line 1. Enter values for the title
and content
attributes on lines 4–5 as part of the request body. Try adding the values for other optional parameters listed in the post attributes table above.
Click the "Run" button to see the output.
blogId = ''data = {'title': '','content': ''}url = 'https://blogger.googleapis.com/v3/blogs/' \+ blogId + '/posts'response = requests.post(url, headers=headers, json=data)printResponse(response)
The above code displays the newly created blog post object that contains the attributes listed in the post properties table above. An appropriate error message will be displayed if the API call fails.
Update a post
We can update a blog post by making a PUT
request to the following URL:
https://blogger.googleapis.com/v3/blogs/{blogId}/posts/{postId}
This endpoint requires the blogId
of the blog that contains the post we want to update, as well as the post’s postId
. We'll also need to provide a post object as part of the request body that contains the fields that we would like to update. We can update any of the fields given in the post attributes table above.
Request parameters
Parameter | Type | Category | Description |
| string | required | The ID of the blog whose post is to be updated. |
| string | required | The ID of the post to be updated. |
Sample code
In the code below, let's change the value of the title
attribute of an existing blog post. Try updating any other attribute(s) listed in the post attributes table above.
Enter the values for the required parameters blogId
and postId
on lines 1–2. Add the new value for the title
attribute on line 5.
Click the "Run" button to see the output.
blogId = ''postId = ''data = {'title': ''}url = 'https://blogger.googleapis.com/v3/blogs/' \+ blogId + '/posts/' + postIdresponse = requests.put(url, headers=headers, json=data)printResponse(response)
The above code displays the complete and updated post object corresponding to the given postId
. This page object contains the attributes listed in the post properties table above. An appropriate error message will be displayed if the API call fails.
Delete a post
We can delete a blog post by making a DELETE
request to the following URL:
https://blogger.googleapis.com/v3/blogs/{blogId}/posts/{postId}
For this endpoint, we'll need to provide the blogId
of the blog that contains the post to be deleted, as well as the postId
corresponding to the post that we would like to delete.
Request parameters
Parameter | Type | Category | Description |
| string | required | The ID of the blog whose post is to be deleted. |
| string | required | The ID of the post to be deleted. |
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/' + postIdresponse = requests.delete(url, headers=headers)printResponse(response)
The above code displays a success message if the specified post object is successfully deleted. An appropriate error message will be displayed if the API call fails.