All Collections
Hashnode API
Query
Fetch Publication Posts
Fetch Publication Posts

Learn how to programmatically fetch all posts made by a user on Hashnode

unclebigbay avatar
Written by unclebigbay
Updated over a week ago

Publication posts are the articles published by a specific user on their Hashnode blog.


In this guide, we'll discuss how to fetch the publication posts made by a specific Hashnode author by using their username.

Requirements

  • Hashnode username i.e "unclebigbay"

  • Few blogs on the publication


User Query

Make use of the "User query" to retrieve a user's publication posts using their username.

You can query the following data from the user publication posts query:

_id: ID!

followersCount: Int

author: User

cuid: String

slug: String

title: String

type: String!

popularity: Float

reactionsByCurrentUser: [Reaction]

totalReactions: Int

bookmarkedIn: [String]

partOfPublication: Boolean

contributors: [Contributor]

isActive: Boolean

replyCount: Int

responseCount: Int

dateAdded: String

tags: [Tag]

brief: String

coverImage: String!

isAnonymous: Boolean

dateUpdated: String

dateFeatured: String

reactions: [Reaction]

poll: Poll

contentMarkdown: String

numUniqueUsersWhoReacted: Int

The user publication posts is a "query" operation to fetch the user's articles, and it expects a username as an argument:

{
user(username: "unclebigbay") {
publication {
posts(page: 0) {
_id
cuid
coverImage
title
}
}
}
}

The query above will return the first page of your publication with six articles:

You can query for additional pages by passing an integer to the page parameter, which will return your additional articles i.e page: 1 will return the next six articles.

If the page parameter is greater than the total number of posts in your publication, an empty array will be returned as follows:

Resources

  • Check out the JavaScript query code here.

Next Articles:

Did this answer your question?