-1

I was trying to create a api web data connector for tableau, but stuck in the authorization phase. I have a header key and value (e.g. api_header, value123) needs to pass using javascript.

// Download the data
    myConnector.getData = function(table, doneCallback) {
        $.getJSON("https://testapi/data",
        
        function(resp) {
        var tableData = [];

How to pass the key and value here?

James Z
  • 12,209
  • 10
  • 24
  • 44
Krish_D
  • 13
  • 5
  • Have you tried `$.getJSON("https://testapi/data", {api_header:'value123'} function(resp) { var tableData = [];` – Asutosh Aug 21 '20 at 05:39

1 Answers1

0

I'm not sure .getJSON supports headers, at least the documentation doesn't mention them.

According to this answer, you could use .ajax instead like so:

$.ajax({
  url: 'https://testapi/data',
  headers: { api_header: 'value123' }
});

Dennis Hackethal
  • 13,662
  • 12
  • 66
  • 115