49

I'm trying to integrate Medium blogging into an app by showing some cards with posts images and links to the original Medium publication.

From Medium API docs I can see how to retrieve publications and create posts, but it doesn't mention retrieving posts. Is retrieving posts/stories for a user currently possible using the Medium's API?

1
  • 2
    does not seem possible for now. Apparently you can only list publications and add a post to a publication. (but you can't even change a post after you created it, and the POST endpoint does not return a Location header with the url to the newly created post.)
    – njzk2
    Mar 19, 2016 at 3:52

11 Answers 11

83

The API is write-only and is not intended to retrieve posts (Medium staff told me)

You can simply use the RSS feed as such:

https://medium.com/feed/@your_profile

You can simply get the RSS feed via GET, then if you need it in JSON format just use a NPM module like rss-to-json and you're good to go.

7
  • 2
    I made a microservice wrapper for the rss-to-json package Antonio was mentioning above that also makes it easy to pull that data down: clay.run/services/nicoslepicos/rss-to-json. If you wanted to parameterize it so the endpoint always just pulls down some specific feed, just fork this endpoint with clay fork nicoslepicos/rss-to-json and then just put in the hardcoded feed you want it to always return. Alternatively, there's this other microservice: clay.run/services/nicoslepicos/medium-get-users-posts, which uses the Medium RSS feed specifically. Mar 6, 2017 at 21:45
  • Is it possible to get medium's front page stories with RSS or something?
    – The Onin
    May 2, 2017 at 15:46
  • 11
    not all the medium posts from an author show in the feed Dec 30, 2019 at 22:53
  • 3
    How to get the next page of a medium feed? Feb 7, 2021 at 5:28
  • Btw, I create a project that you can embed medium articles into your Readme. Check it out: github.com/tonynguyenit18/github-readme-social-article Apr 4, 2021 at 1:20
13

Edit:

It is possible to make a request to the following URL and you will get the response. Unfortunately, the response is in RSS format which would require some parsing to JSON if needed.

https://medium.com/feed/@yourhandle

⚠️ The following approach is not applicable anymore as it is behind Cloudflare's DDoS protection.

If you planning to get it from the Client-side using JavaScript or jQuery or Angular, etc. then you need to build an API gateway or web service that serves your feed. In the case of PHP, RoR, or any server-side that should not be the case.

You can get it directly in JSON format as given beneath:

https://medium.com/@yourhandle/latest?format=json    

In my case, I made a simple web service in the express app and host it over Heroku. React App hits the API exposed over Heroku and gets the data.

const MEDIUM_URL = "https://medium.com/@yourhandle/latest?format=json";

router.get("/posts", (req, res, next) => {
  request.get(MEDIUM_URL, (err, apiRes, body) => {
    if (!err && apiRes.statusCode === 200) {
      let i = body.indexOf("{");
      const data = body.substr(i);
      res.send(data);
    } else {
      res.sendStatus(500).json(err);
    }
  });
});
2
  • is there a way to get the single post content? Aug 5, 2019 at 16:25
  • 7
    This is no longer valid. Cloudflare is adding a captcha challenge unfortunately.
    – Harry Theo
    Apr 11, 2020 at 13:10
11

Nowadays this URL:

https://medium.com/@username/latest?format=json

sits behind Cloudflare's DDoS protection service so instead of consistently being served your feed in JSON format, you will usually receive instead an HTML which is suppose to render a website to complete a reCAPTCHA and leaving you with no data from an API request.

And the following:

https://medium.com/feed/@username

has a limit of the latest 10 posts.

I'd suggest this free Cloudflare Worker that I made for this purpose. It works as a facade so you don't have to worry about neither how the posts are obtained from source, reCAPTCHAs or pagination.

Full article about it.

Live example. To fetch the following items add the query param ?next= with the value of the JSON field next which the API provides.

2
  • I was using your solution, but I think they recently modified something on their end that made the solution not work anymore :( Oct 5, 2020 at 12:57
  • https://medium.com/feed/@username also includes data of comments I have made on my own or other stories. So separating them from actual stories is not possible it seems
    – Biboswan
    Oct 22, 2020 at 8:42
10

To get your posts as JSON objects

you can replace your user name instead of @USERNAME.

https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@USERNAME

9
const MdFetch = async (name) => {
  const res = await fetch(
    `https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/${name}`
  );
  return await res.json();
};

const data = await MdFetch('@chawki726');

6

With that REST method you would do this: GET https://api.medium.com/v1/users/{{userId}}/publications and this would return the title, image, and the item's URL. Further details: https://github.com/Medium/medium-api-docs#32-publications .

You can also add "?format=json" to the end of any URL on Medium and get useful data back.

1
  • 7
    it's tricky but when they say "publications" they don't mean "user's posts". As Antonio says the only way to access user's posts is through RSS. See this issue
    – damko
    Jan 28, 2017 at 2:37
4

Use this url, this url will give json format of posts
Replace studytact with your feed name

https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/studytact

0
2

I have built a basic function using AWS Lambda and AWS API Gateway if anyone is interested. A detailed explanation is found on this blog post here and the repository for the the Lambda function built with Node.js is found here on Github. Hopefully someone here finds it useful.

1
  • Wrapped that AWS Lambda you created into a Clay microservice. Also, as a heads up tried to send you an email to tell you about it but looks like the email on your site is bouncing back :) Mar 6, 2017 at 21:46
1

(Updating the JS Fiddle and the Clay function that explains it as we updated the function syntax to be cleaner)

I wrapped the Github package @mark-fasel was mentioning below into a Clay microservice that enables you to do exactly this:

Simplified Return Format: https://www.clay.run/services/nicoslepicos/medium-get-user-posts-new/code

I put together a little fiddle, since a user was asking how to use the endpoint in HTML to get the titles for their last 3 posts: https://jsfiddle.net/h405m3ma/3/

You can call the API as:

curl -i -H "Content-Type: application/json" -X POST -d '{"username":"nicolaerusan"}' https://clay.run/services/nicoslepicos/medium-get-users-posts-simple

You can also use it easily in your node code using the clay-client npm package and just write:

Clay.run('nicoslepicos/medium-get-user-posts-new', {"profile":"profileValue"})
.then((result) => {

  // Do what you want with returned result
  console.log(result);

})
.catch((error) => {

  console.log(error);

});

Hope that's helpful!

0

Check this One you will get all info about your own post........

mediumController.getBlogs = (req, res) => {
    parser('https://medium.com/feed/@profileName', function (err, rss) {
        if (err) {
            console.log(err);
        }

        var stories = [];

        for (var i = rss.length - 1; i >= 0; i--) {

            var new_story = {};

            new_story.title = rss[i].title;
            new_story.description = rss[i].description;
            new_story.date = rss[i].date;
            new_story.link = rss[i].link;
            new_story.author = rss[i].author;
            new_story.comments = rss[i].comments;

            stories.push(new_story);
        }
        console.log('stories:');
        console.dir(stories);
        res.json(200, {
            Data: stories
        })
    });

}
2
  • 1
    what is mediumController, even?
    – jpls93
    Nov 23, 2018 at 11:15
  • 1
    NodeJs Controller, I guess. As I see syntax is of NodeJS. Mar 26, 2019 at 7:31
0

I have created a custom REST API to retrieve the stats of a given post on Medium, all you need is to send a GET request to my custom API and you will retrieve the stats as a Json abject as follows: Request :

curl https://endpoint/api/stats?story_url=THE_URL_OF_THE_MEDIUM_STORY

Response:

{
   "claps": 78,
   "comments": 1
}

The API responds within a reasonable response time (< 2 sec), you can find more about it in the following Medium article.

Not the answer you're looking for? Browse other questions tagged or ask your own question.