Nat Bradley
Nat Bradley

Reputation: 13

How to convert a cURL request into a Google Apps Script UrlFetchApp

I'm aware this is probably basic stuff.

I've read a lot of the other questions on here around converting cURL into a Google Apps Script UrlFetchApp request however, I'm unable to get it to work. I'm a marketer, not a developer, so I have limited knowledge of Javascript but I'm usually able to manipulate reference scripts for my own needs. This one just won't work for me.

All I get is "Authentication has failed" as a response.

My current code is:

function wisepopsData() {
  var API_KEY = 'APIKEYHERE';
  var root = 'https://app.wisepops.com/api1/wisepops';
  var params = {
    'headers': {
      'Authorization': 'WISEPOPS-API ' + Utilities.Base64Encode(API_KEY)
    }
  };
  var response = UrlFetchApp.fetch(root, params);
  var data = response.getContentText();
  var json = JSON.parse(data);
  Logger.log(json);
}

The documentation I'm using is below. I'm trying to implement the performance data part --> https://support.wisepops.com/en/articles/572165-wisepops-api-basics#performance-data-on-your-wisepops

The part I can't get my head around is 'Authorization: WISEPOPS-API key="YOUR_API_KEY_HERE"'. I've tried lots of combinations in the header of the request to get this bit to work and still nothing.

Upvotes: 0

Views: 1461

Answers (1)

Ameya Joshi
Ameya Joshi

Reputation: 404

Try changing params variable intialization. something like :

var params = {
'headers': {
  'Authorization': 'WISEPOPS-API key="' + API_KEY + '"'
}};

Upvotes: 3

Related Questions