How to pass token for making API calls?

Hi N8N Team,
After integrating n8n in our product, I am removing the credentials dropdown and getting token from my DB and trying to pass the token for my API calls, while doing that i am getting error like "‘Authentication credentials were not provided.’ '"for the below code and n8n is getting terminated in terminal

Attached the code below

rpa_name = (await abmsInternalApiRequest.call(
						this,
						'GET',
						endpoint,
						{},
						jwtToken,
					)) as LoadedResource[];

export async function abmsInternalApiRequest(
	this: IExecuteFunctions | ILoadOptionsFunctions,
	method: string,
	endpoint: string,
	body: IDataObject = {},
	jwtToken: any


) {
	const credentials = (await this.getCredentials('abmsApi')) as AbmsCredentials;

	const options: OptionsWithUri = {
		method,
		body,
		uri: `${credentials.host}${endpoint}`,
		json: true,
		rejectUnauthorized: !credentials.allowUnauthorizedCerts,
		headers: {
'token': {jwtToken}
}
	};
	
	try {
		return await this.helpers.request!(options);
	} catch (error) {
		throw new NodeApiError(this.getNode(), error);
	}
}

I have replaced

auth: {
	 	user: credentials.username,
	 	pass: credentials.password,
		 },

by

		headers: {
'token': {jwtToken}
}

in the code after that this error coming , before it was working fine.
can you give me any example of how to pass the token for API calls?

Regards,
Praveen

Hey @praveen,

What is the exact error you are getting? Looking at the code you have passed I can see a credentials const being used which I guess you have already checked.

One thing it could be is the token value you are sending, What are you expecting to get and have you outputted the options object to the console to inspect it?

I think you will need the below but the information is a bit limited.

headers: {
  'token': jwtToken
}

Hi @Jon ,
I am using credentials for getting host, later i will replace by giving in env file.Exact error i am getting is

Hi @praveen,

Have you changed the header like I suggested? From what I can see it is the other service throwing a 403 error and I suspect it is the header causing the problem.

yeah @Jon I have changed the header like you suggested. still getting the error like
“”
httpCode: ‘403’,
description: ‘Authentication credentials were not provided.’
“”

Hey @praveen,

Have you checked the sent data to make sure it is what you are expecting to be sent? The server you are sending data to is returning the 403 so it could be that something else is missing.