DEV Community

hmza
hmza

Posted on

πŸš€ Getting Started with the Dev.to API

πŸš€ Getting Started with the Dev.to API

"If content is king, then automation is the kingdom." β€” Probably a developer on Dev.to


πŸ€” What is the Dev.to API?

The Dev.to API is a RESTful API provided by DEV Community that allows developers to interact with their content programmatically.

You can:

  • Read articles
  • Publish new posts
  • Update existing posts
  • Manage comments
  • And more...

Yes, that means you can post blog entries straight from your CLI or your CI pipeline. Nerd paradise.


🧰 Prerequisites

  • A Dev.to account
  • An API key from your account settings
  • A tool like curl, Postman, or any HTTP client in your favorite language

πŸ” Authentication

The API uses a bearer token.

Example:

curl -H "api-key: YOUR_DEVTO_API_KEY" https://dev.to/api/articles/me
Enter fullscreen mode Exit fullscreen mode

Replace YOUR_DEVTO_API_KEY with your personal API key.


πŸ“ Creating an Article

Here’s how to create a draft article using curl:

curl -X POST https://dev.to/api/articles \
  -H "Content-Type: application/json" \
  -H "api-key: YOUR_DEVTO_API_KEY" \
  -d '{
    "article": {
      "title": "Why Coffee Should Be a Frontend Framework β˜•",
      "published": false,
      "body_markdown": "# CoffeeScript returns\n\nWe were wrong to abandon it..."
    }
  }'
Enter fullscreen mode Exit fullscreen mode

If "published" is set to true, the post goes live immediately. Boom.


πŸ“– Fetching Your Articles

Want to retrieve all of your articles?

curl -H "api-key: YOUR_DEVTO_API_KEY" https://dev.to/api/articles/me
Enter fullscreen mode Exit fullscreen mode

Need just one?

curl -H "api-key: YOUR_DEVTO_API_KEY" https://dev.to/api/articles/123456
Enter fullscreen mode Exit fullscreen mode

✏️ Updating an Article

curl -X PUT https://dev.to/api/articles/123456 \
  -H "Content-Type: application/json" \
  -H "api-key: YOUR_DEVTO_API_KEY" \
  -d '{
    "article": {
      "title": "Updated Title",
      "body_markdown": "# New body\nUpdated with automation!"
    }
  }'
Enter fullscreen mode Exit fullscreen mode

πŸ—‘οΈ Deleting an Article

You can delete an article by hitting:

curl -X DELETE https://dev.to/api/articles/123456 \
  -H "api-key: YOUR_DEVTO_API_KEY"
Enter fullscreen mode Exit fullscreen mode

No takesies backsies. πŸ’€


πŸ”„ Bonus: Automate Your Blog Workflow

You can use:

  • Python + requests
  • Node.js + axios
  • GitHub Actions
  • Bash + cronjobs

...to automate publishing your blogs, syncing content from GitHub, or triggering posts based on events.


πŸ“š Resources


πŸ’‘ Final Thought

"A real developer posts blogs with curl."

Now go forth and blog like a dev god. πŸ› οΈπŸ“€

Top comments (0)