Skip to main content

Command Palette

Search for a command to run...

How to Publish Blog Posts on Hashnode Manually

Updated
3 min read
How to Publish Blog Posts on Hashnode Manually

How to Publish Blog Posts on Hashnode Manually

Complete guide to publish blog posts on Hashnode using GraphQL API.

Prerequisites

  1. Hashnode account with a blog
  2. Personal Access Token
  3. Blog URL

Step 1: Get Your Hashnode Token

  1. Go to Hashnode
  2. Click on Settings → API Tokens
  3. Click "Generate new token"
  4. Copy the token (save it securely)

Step 2: Get Your Publication ID

Run this GraphQL query:

curl -X POST https://gql.hashnode.com/ \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_TOKEN_HERE" \
  -d '{
    "query": "query { me { username publications(first: 10) { edges { node { id title url } } } } }"
  }'

Response:

{
  "data": {
    "me": {
      "username": "your-username",
      "publications": {
        "edges": [
          {
            "node": {
              "id": "6875dce83b0919f1c1394d62",
              "title": "Your Blog Title",
              "url": "https://yourblog.hashnode.dev"
            }
          }
        ]
      }
    }
  }
}

Copy the id field - this is your Publication ID.

Step 3: Prepare Your Blog Post

Write your content in Markdown format:

---
title: Your Post Title
---

# Introduction

Your content here...

## Features

- Feature 1
- Feature 2

## Conclusion

Wrap up!

Step 4: Publish the Post

Use this GraphQL mutation:

curl -X POST https://gql.hashnode.com/ \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_TOKEN_HERE" \
  -d '{
    "query": "mutation PublishPost($input: PublishPostInput!) { publishPost(input: $input) { post { title url slug } } }",
    "variables": {
      "input": {
        "publicationId": "YOUR_PUBLICATION_ID",
        "title": "Your Post Title",
        "contentMarkdown": "# Your Post Title\n\nYour markdown content here..."
      }
    }
  }'

Response:

{
  "data": {
    "publishPost": {
      "post": {
        "title": "Your Post Title",
        "url": "https://yourblog.hashnode.dev/your-post-slug",
        "slug": "your-post-slug"
      }
    }
  }
}

Step 5: Delete a Post (Optional)

First, get the post ID:

curl -X POST https://gql.hashnode.com/ \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_TOKEN_HERE" \
  -d '{
    "query": "query { publication(host: \"yourblog.hashnode.dev\") { posts(first: 10) { edges { node { id slug title } } } } }"
  }'

Then delete:

curl -X POST https://gql.hashnode.com/ \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_TOKEN_HERE" \
  -d '{
    "query": "mutation RemovePost($input: RemovePostInput!) { removePost(input: $input) { post { slug } } }",
    "variables": {
      "input": {
        "id": "POST_ID_HERE"
      }
    }
  }'

Common Issues

1. Invalid Token

  • Error: Unauthorized
  • Solution: Check your token is correct and not expired

2. Wrong Publication ID

  • Error: Publication not found
  • Solution: Get your publication ID again from Step 2

3. Markdown Format

  • Error: Invalid markdown
  • Solution: Escape quotes and special characters properly

Example: Complete Script

Save this as publish.sh:

#!/bin/bash

TOKEN="your_token_here"
PUB_ID="your_publication_id"
TITLE="My New Post"
CONTENT="# My New Post\n\nThis is my content..."

curl -X POST https://gql.hashnode.com/ \
  -H "Content-Type: application/json" \
  -H "Authorization: $TOKEN" \
  -d "{
    \"query\": \"mutation PublishPost(\$input: PublishPostInput!) { publishPost(input: \$input) { post { title url slug } } }\",
    \"variables\": {
      \"input\": {
        \"publicationId\": \"$PUB_ID\",
        \"title\": \"$TITLE\",
        \"contentMarkdown\": \"$CONTENT\"
      }
    }
  }"

Make it executable:

chmod +x publish.sh
./publish.sh

Next Steps

Now you can:

  • Automate with cron jobs
  • Integrate with CI/CD
  • Build custom tools
  • Use with OpenClaw for AI-powered blogging

More from this blog

M

Masud Rana

8 posts

I am highly skilled full-stack software engineer specializing in Laravel, PHP, JS, React, Vue, Inertia.js, and Shopify, with strong experience in Filament Frontend and prompt engineering.