API get request with authentication

I would like to call API from custom installation page in freshservice. I will get api key from input field and pass it to the headers.

var serviceApiKey = jQuery(“input[name=service_apiKey]”).val();
var headers = {“Authorization”: “Basic <%= encode(serviceApiKey) %>”};
The response is - Error while substituting the templates & status: 400
How can I handle this.
Another:
What is <%= %>

Hi @Gokulaselvan_T!

I hope you are safe and well.

In the settings page, we are unable to use the headers like this. Instead we can use like this,

let options = {
  headers: {
    "Authorization": `Basic ${btoa(apikey)}`,
    "Content-Type": "application/json"
  }
};

I hope this will helps you.

3 Likes

Thank you for your quick reply. Yes that works fine

2 Likes