How to provide an API key for ssl-vp.com in a Google Sheets script?

点点圈 提交于 2020-04-18 07:13:50

问题


I'm trying to get JSON data from a URL and insert the data in the sheets of Google Sheets. The problem is when I try to get the data this response me that error:

Error in the request for the returned code 401 of https://ssl-vp.com/rest/v1/Campaigns/1236223656534991/Recipients?by=ExternalId&page=1&itemsPerPage=500. Truncated server response: Unauthorized Cannot get campaign contacts (use the muteHttpExceptions option to examine the entire response) (line 15, file "Código")

I try to insert the API KEY in the URL but the response is the same error

function myFunction(){
var url = "https://ssl-vp.com/rest/v1/Campaigns/1236223656534991/Recipients?by=ExternalId&page=1&itemsPerPage=500";
var apiKey = "xxxxxxxxxxxxxxxxxxxxx";
  var header={
    "headers":{
         "X-API-KEY":apiKey
    }
  };
var response = UrlFetchApp.fetch(url,header);
  Logger.log(response.getContentText());
}

回答1:


According to ssl-vp.com's API docs, this service expects the API key in the Authorization header like so:

Authorization: Bearer <API_KEY>

Change your code to:

var header = {
  "headers": {
    "Authorization": "Bearer " + apiKey
  }
};


来源:https://stackoverflow.com/questions/57003438/how-to-provide-an-api-key-for-ssl-vp-com-in-a-google-sheets-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!