Reputation: 11
So i am getting trouble in passing the token which my api uses as header, I tried in postman api works fine, Its an internal api.
Whereas when it come to code which is present in appscript it works fine with open apis but when I try to use my own internal api it throws error as :
Exception: Request failed for https://api.rupeek.com returned code 401. Truncated server response: {"message":"Bad authentication"}
sharing the appscript code below : tag-name
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Rupeek Menu')
.addItem('Get Ref ID','displayrefid')
.addToUi();
}
// function to call Rupeek API
function callrpkAPI(rpk) {
// Call the Rupeek api
var url = 'api url';
var response = UrlFetchApp.fetch(url, token);
var token = {
"method": "get",
"headers": {
"Authorization": "MY JWT token passing here ",
"Accept": "application/json",
},
"contentType": "application/json",
"body": "phone",
};
// Parse the JSON reply
var json = response.getContentText();
return JSON.parse(json);
}
function displayrefid() {
// pick up the search term from the Google Sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var ref = sheet.getRange(4,2).getValue();
var id = callrpkAPI(ref);
var results = id["results"];
var output = []
// clear any previous content
sheet.getRange(15,1).clearContent();
// paste in the values
sheet.getRange(15,1).setValues(sortedOutput);
}
Please let me know if you guys get the solution for this stuck in this for last 2 days.
So i am getting trouble in passing the token which my api uses as header, I tried in postman api works fine, Its an internal api.
Whereas when it come to code which is present in appscript it works fine with open apis but when I try to use my own internal api it throws error as :
Exception: Request failed for https://api.rupeek.com returned code 401. Truncated server response: {"message":"Bad authentication"}
Upvotes: 1
Views: 69