HTTP GET request from javascript



I wrote the following javascript code to send a HTTP request, to get data from a dataport.

var xhr = new XMLHttpRequest();‘GET’, “/api/portals/v1/portals//alias?”, true);

This doesn’t work. I tried adding authentication and still didn’t work.
xhr.setRequestHeader(“Authorization”, “Basic " + btoa(”" + “:” + “”));

I found the following link, which explains how to add GET request to a widget in the portals page. But I need the request to work in my website.

Here is a basic sketch:

<!DOCTYPE html>
<meta charset="utf-8">
<meta lang=en>
    function myFunction() {
        var xhr = new XMLHttpRequest();'GET', "/api/portals/v1/portals/**<insert CIK here>**/alias?**<insert alias here>**", true);
<link rel="stylesheet" href="_styles/styles.css">
    <button onclick="myFunction()">Click me</button>
Can you help me fix this? @Martin @MikeA @willcharlton

Kind regards,


@Vijay -

Is this code meant to be run in your own application or within a widget on your Portals page?

Either way you cannot use a CIK for authentication or a relative path to the API. Check out the documentation for the Portals API to fetch a dataport’s data

curl '<device_rid>/data' \
     -X GET \
     -u '' \

This is likely the call that you will want to use to fetch your data.

Happy to help,


Hi Martin,

This is a standalone web application outside of Portals. It is a web app which will display live data trending based on data from one of my device’s data ports. I did see this Portals curl API. How do I integrate this into my javascript code of my web application?

Are there any samples?

Kind regards,



I made the mistake of only now remembering that neither the RPC API or the Portals API support CORS. This means that you will not be able to use the visiting client’s browser of your site to make these requests.

A worker or process in your application will have to be responsible for fetching data via an API and then changing the client’s document.

This also has the tradeoff of allowing you to make use of the RPC API. We know that the RPC API will be more performant.

I don’t have open source code of an application that has implemented this, but I have personally helped work on them and can answer questions. There applications typically store a the subdomain’s root CIK as an environment variable to authenticate all of the RPC API requests the application needs to make.



Are you talking about this?


That repository is a set of Node bindings around our RPC API, it could be of a lot of use in your JavaScript based application. Feel free to download that code and use it!

This is likely the documentation that you will want to consume:


Hi Martin,

Thanks for your reply.

Kind regards,