I can throw this into a linux terminal and get results.
curl -H "Authorization: Token token={api_token}" \
-X GET \
"https://api.callrail.com/v2/a/{account_id}/calls.json?company_id={companyId}"
Here is what I have:
var myToken = "fakeToken1234";
$.ajax
({
type: "GET",
url: "https://api.callrail.com/v2/a/{accountId}/calls.json?company_id={companyId}",
dataType: 'json',
beforeSend: function (xhr) { xhr.setRequestHeader('Authorization:', + myToken ); }
});
Per CallRail Documentation I'm supposed to pass the api_token into HTTP Authorization header. I get a 401 Unauthorized message.
I think my syntax is off but can't pin it down. Any help?
My problem was I didn't understand the syntax that CallRail wanted in the header.
This solved it: headers: { "Authorization": 'Token token=' + myToken },
var myToken = "token1234";
var accountId = "Id1234";
var companyId = "Id1234";
$.ajax
({
type: "GET",
url: "https://api.callrail.com/v2/a/" + accountId + "/calls/timeseries.json?company_id=" + companyId + "",
dataType: 'json',
headers: { "Authorization": 'Token token=' + myToken },
success: function (result) {
console.log(result);
},
});
This is what I would try using "headers:":
let companyId = "";
let accountId = "";
let myToken = "fakeToken1234";
$.ajax({
type: "GET",
url: `https://api.callrail.com/v2/a/${accountId}/calls.json?company_id=${companyId}`,
headers: {"Authorization": `Token token="${myToken}"`},
dataType: 'json'
});
Don't forget to also load the companyId and accountId in your url. I am assuming you are using the right url in this answer by the way.
Hope it works. I only did $.ajax requests with one API so far. So let me hear if it works. It should at the very least point you in the right direction.