Skip to main content
Fetch Publication Posts

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

Updated over 10 months 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 account using their host name and publication ID.

Requirements

  • Host name i.e. "favouritejome.hashnode.dev" or "blog.favouritejome.dev" (notice without the protocol - https, attached to the domain URL)


Publication Query

The publication query retrieves a user's publication details based on either their publication ID or their host name.

Note: You can't use both arguments, id and host (i.e. publication ID and host name) at the same time for this query. You'll have to pick one of the arguments while using the query.

If you'd like to see the entire list of fields that can be retrieved from the publication query, please visit the documentation

Using the host name

Here's an example of how the query would be written:

query Publication(
$host: String
) {
publication(
host: $host
) {
id
title
displayTitle
about {
text
}
url
author {
id
username
name
}
posts(first: 3) {
edges {
node {
title
}
}
totalDocuments
}
}
}

The query above returns the first three posts of the publication:

Using publication ID

There are two methods to know the publication ID. The first method is by making use of the publication query with the host name argument and retrieving the id field. Here's how to do so:

query Publication(
$host: String
) {
publication(
host: $host
) {
id
}
}

Here's an example using our API playground, with the host name as blog.favouritejome.dev to get the publication ID as 5f5f88cc93fd9275f04d3a5f

The second method will be to get the ID from your dashboard URL on Hashnode.

Note: We recommend making use of the host name instead of the publication ID.

Next Articles:

Did this answer your question?