<!-- Auth via header -->
<div>
  MSFT:<img id="headerAuth" />
</div>

<!-- Auth via URL param -->
<div id="urlAuth">AAPL:</div>
//----------------------------------
//  Auth Token in Header  
//----------------------------------

// Set the chart inputs
var chartInputs = {
  "symbol": "MSFT",
  "exchange": "NSQ"
};

// Stringify & Encode Inputs
var encoded = encodeURIComponent(JSON.stringify(chartInputs, null));

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if (this.readyState == 4 && this.status == 200){
        console.log(this.response, typeof this.response);
        var img = document.getElementById("headerAuth");
        var url = window.URL || window.webkitURL;
        img.src = url.createObjectURL(this.response);
    }
}
xhr.open("GET", "https://api.markitondemand.com/apiman-gateway/MOD/chartworks-image/1.0/Chart/sparkLine?inputs=" + encoded);
// Set the header token
xhr.setRequestHeader("Authorization", "Bearer demo-token");
xhr.responseType = "blob";
xhr.send();



//----------------------------------
//  Auth Token as URL Param  
//----------------------------------

// Set the auth token
var token = "demo-token";

// Set the chart inputs
var chartInputs = {
  "symbol": "AAPL",
  "exchange": "NSQ"
};

// Stringify & Encode Inputs
var encoded = encodeURIComponent(JSON.stringify(chartInputs, null));

// Create API call with "access_token" parameter on URL string
var url = "https://api.markitondemand.com/apiman-gateway/MOD/chartworks-image/1/Chart/sparkLine?inputs=" + encoded + "&access_token=" + token;

// Append to our target
$("<img />").attr("src", url).appendTo("#urlAuth");

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. //cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js