Using the new Microreact API


(the excellent) Microreact has recently had a major new release which has a few breaking changes. One that hit me is that the API has changed. The previous API was pretty simple, and allowed anonymous POST requests with a blob of CSV, tree and optionally network to return a stable URL.

The new API requires a token for authorisation and addition to your account (which seems sensible), and also adds deletion and updating of instances (which is also useful). There are some docs on migrating, and while creating the API token is easy enough, I had a bit of trouble converting my existing code.

So, here is my advice on how to use the new API:

  • If you’re a JSON whizz the new schema is here, but if not I found it helpful to save an existing plot (there’s a new option in the GUI for this) and look through in a JSON browser.
  • Don’t use the conversion endpoint. I found it a little fiddly, and it didn’t seem to support the network plot. Instead, download a .microreact JSON from one of your projects and modify it as necessary.
  • Files can still be provided as strings using the blob attribute.
  • In python, you can use the json and requests packages to do this pretty easily, and just change dictionary entries.

You can find my final working code in PopPIPE.