π 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
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..." } }'
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
Need just one?
curl -H "api-key: YOUR_DEVTO_API_KEY" https://dev.to/api/articles/123456
βοΈ 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!" } }'
ποΈ 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"
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
- π Dev.to API Docs
- π§° Forem Open Source
- π Get your API key here
π‘ Final Thought
"A real developer posts blogs with
curl
."
Now go forth and blog like a dev god. π οΈπ€
Top comments (0)