How to retrieve Medium stories for a user from the API?

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.


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);
    }
  });
});

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.


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');

Tags:

Medium.Com