Getting data from emoncms into a web site using API


I’ve been fiddling around with Sankey Diagram & How To Create It with JavaScript which I think could be used to create a dynamic home Sanke Diagram like this:

However, I’ve never built any web pages using Javascript before and whilst I’ve managed to get the Sanke to work (in jsfiddle for the moment) I have tried and tried to read the emoncms feed API with various diffrent approaches I’ve found on the web, but can never get it to return any data. Can anyone provide a bit of JavaScript that would read the lates feed value into a variable which I can subsequently use in the sanke diagram? Happy to share results after I’ve got it working :slight_smile:

In the top right of the Feeds page, you should see this;


It should have all you need to read the data via the API.

Can’t help with the Javascript, I’m afraid.

Thanks - unfortunately it’s the javascript that Ican’t get to work. I’ve used the API extensively to Pull and push things to and fro NodeRed for various calculations, but I just can’t seem to work out how to write the script to make that work in a web page.


1 Like

The problem may be the Same-origin policy - Web security | MDN which you might overcome by setting CORS HTTP headers, or by emoncms’s trick of proxying the remote data through a URL on the same host.

To see if that’s the case, check your browser’s Developer Tools Javascript console when it fails to load the data.