Create, Update, and Delete a Post

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

kind

string

The type of object.

Value: "blogger#post"

Note: This value is fixed.

id

string

The ID of the post.

blog

object

The object that contains the post's blog data.

blog.id

string

The ID of the post's blog.

published

datetime

The post's publishing date.

Format: yyyy-mm-dd

updated

datetime

The date of the post's last update.

Format: yyyy-mm-dd

url

string

The published link of the post.

selfLink

string

The Blogger API URL of the post.

title

string

The title of the post.

content

string

The content of the post.

Note: This value can include HTML.

author

object

The object that contains the post's author information.

author.id

string

The ID of the post's author.

author.displayName

string

The name of the post's author.

author.url

string

The published link of the author profile.

author.image

object

The object that contains the author's avatar information.

author.image.url

string

The URL of the author avatar.

replies

object

The object that contains the post's comments.

replies.totalItems

long

The number of comments on the post.

replies.selfLink

string

The Blogger API URL of the post's comments.

labels[]

list

The list of tags associated with the post.

customMetaData

string

The metadata of the post.

replies.items[]

list

The list of comments on the post.

location

object

The object that contains the location information of the post.

Note: This value is only available if the post was geotagged.

location.name

string

The name of the post's location.

location.lat

double

The latitude of the post's location.

location.lng

double

The longitude of the post's location.

location.span

string

The viewport span of the post's location.

titleLink

string

The URL of the title.

images[]

list

The post's display image.

images[].url

string

The URL of the post's display image.

status

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

blogId

string

required

The ID of the blog to add the post to.

isDraft

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.

Press + to interact
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

blogId

string

required

The ID of the blog whose post is to be updated.

postId

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.

Press + to interact
blogId = ''
postId = ''
data = {
'title': ''
}
url = 'https://blogger.googleapis.com/v3/blogs/' \
+ blogId + '/posts/' + postId
response = 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

blogId

string

required

The ID of the blog whose post is to be deleted.

postId

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.

Press + to interact
blogId = ''
postId = ''
url = 'https://blogger.googleapis.com/v3/blogs/' \
+ blogId + '/posts/' + postId
response = 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.