DEV Community

Cover image for Dev.to API 002 - Creating a Post
Rodrigo Cordeiro
Rodrigo Cordeiro

Posted on

Dev.to API 002 - Creating a Post

002 - Creating a Post with the API

Ok, now we already know what to do to get the feed and the basic to work with the API, so, now we're going to post something using the API. To this, we must send a POST request to /articles with a the information about the post, see all the parameters possibilities at the api documentation.

curl

curl --request POST  
--url https://dev.to/api/articles  
--header 'api-key: YOUR_API_TOKEN'  
--header 'content-type: application/json'  
--data '{ 
 "article": { 
     "title": "Creating new post", 
     "published": true, 
     "body_markdown": "Hey there, here go some post.", 
     "tags": [ 
         "todayilearned", 
         "showdev" 
     ]
 }
}'

node

var unirest = require("unirest");

unirest.post('https://dev.to/api/articles')
 .type('json')
 .headers({
   'api-key':'YOUR_API_TOKEN'
 })
 .send({
   "article": {
     "title": "Creating new post",
     "published": true,
     "body_markdown": "Hey there, here go some post.",
     "tags": [
       "todayilearned",
       "showdev"
     ]
   }
 })
 .then((response)=>{
   console.log(response.body)
 })

That's all folks!! You can see all the steps on my documentation.

Top comments (0)