How to use Medium.com API to publish content

Medium.com provides an API to publish content directly to the site. Learn how to use their API

Step 1: Go to medium.com and open the settings tab

Step 2: Find  ‘add integration’ and get your token

Step 3: Replace your token in place of xxxx in the given url https://api.medium.com/v1/me?accessToken=XXXX

Step 4: Copy user Id and and replace it in the following code

var request = require('request');

var token = 'XXXX'; //get one at https://medium.com/me/settings scroll to the very end of the page and 'add' integration token
var userId = 'YYYY'; //open this link https://api.medium.com/v1/me?accessToken=XXXX in your browser and get your userid there

var post_data = {
	'title' : 'Post title',
	'contentFormat' : 'html',
	'content': '<p>Test HTML post</p>',
	'canonicalUrl': 'https://Original-Url', //this one is important to avoid SEO issues
	'publishStatus': 'draft'
};

console.log(post_data);

console.log('Sending the post request...');

// Set up the request
request({
	url: 'https://api.medium.com/v1/users/' + userId + '/posts',
	method: 'POST',
	json: true,
	headers: {
		'Authorization': 'Bearer ' + token,
        	"content-type": "application/json"
    	},
	body: post_data
	},
	function (error, response, body) {
		console.log(body);
		console.log(error);
	});