I've been trying to get all candidates from Catsone into a Google Sheet and although the code is apparently according to their API instruction, I'm getting the above mentioned error and I'm not sure where to look for the issue.
Here's the code I'm running:
const API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXX";
function getallcandidates() {
const url = 'https://api.catsone.com/v3/candidates';
const params = {
'muteHttpExceptions': true,
'method': 'GET',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Token' + API_KEY
}
};
const response = UrlFetchApp.fetch(url, params);
const data = response.getContentText();
const json = JSON.parse(data);
Logger.log('Data: ' + json)
}
These are their instructions for authentication: https://docs.catsone.com/api/v3/#authentication
This is what successfully I got whe I tried calling it from Postman:
var myHeaders = new Headers();
myHeaders.append("Authorization", "Token XXXXXXXXXXXXXXXXXXXX");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://api.catsone.com/v3/candidates", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Appreciate any help.
When I saw your added Javascript and your Google Apps Script, if the value of const API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXX";
has no space at the top character, how about the following modification?
'Authorization': 'Token' + API_KEY
'Authorization': 'Token ' + API_KEY
'Token'
is modified to 'Token '
.