Hello, I’m working on creating a pack with authentication and fetching data from API, for successful response API requires custom authentication header, I’m quite confused about what to use for my case
right now it’s
for now authentication code is like this
pack.setUserAuthentication({
type: coda.AuthenticationType.CustomHeaderToken,
headerName: "Authorization",
tokenPrefix: "Token",
endpointDomain: "${ENDPOINT_DOMAIN}",
instructionsUrl: "${INSTRUCTIONS_URL}",
// Determines the display name of the connected account.
getConnectionName: async function (context) {
let url = "${API_URL}"
let response = await context.fetcher.fetch({
method: "GET",
url: url,
});
return response.body.first_name;
},
});
and I’ve got
execute: async function ([id], context) {
let secretHeader = "Authorization {{" + context.invocationToken + "}}";
// I need header here, but in debug panel nothing seen
let response = await context.fetcher.fetch({
method: "GET",
url: "${API_URL}",
headers: { "Authorization": secretHeader}
});
let requestRes = response.body
console.log(requestRes)
let result = [];
return {
result: result,
};
},
how should I implement authentication and data fetching to add custom header to requests?
Hi @andreysukhov90 - Your authentication configuration looks correct, and it should cause the following header to be added to outgoing requests automatically:
Authorization: Token {USER_TOKEN}
As for you execute code, you shouldn’t need to set any headers at all. You seem to be using the pattern required for Custom authentication, which is different than CustomHeader authentication.
I’d recommend removing the all of the authentication and header code from your execute function and see if it works.
is it any specific thing that i should do about addSyncTable that I miss? maybe you can give an advice how it works with authorization? sorry for hurry, got to complete the taks