Freshsales hitting leads api response 401

hitting leads api in published custom app but getting this error … it is working fine in local …

{status: 401, headers: {…}, response: “{“login”:“failed”,“message”:“Incorrect or expired API key”}”, errorSource: “APP”, attempts: 1}

Hi @Surendar_N,
Welcome to our developer’s community :smile:

{status: 401, headers: {…}, response: “{“login”:“failed”,“message”:“Incorrect or expired API key”}”, errorSource: “APP”, attempts: 1}

Since you got the above error message, Have you verified the current API key of your account matches with that you are using for authorization?. If not, Please verify the API key by getting into the settings page!

Thank you :blush:

1 Like

Hi @Anand_Chandran yes am using the current api key of my account … while rendering in local it works . but for a published custom app it give response 401 while trying to hit leads and contacts api

Hi @Surendar_N,
Could you please share the snippet of your code using for your authorization and also the format of authorization token you are sending?. This may be helpful to find out the problem.

Hi , @Anand_Chandran
this is the function where am trying to call the api ,

function leadsList(domain){
    var headers = {"Authorization": "Token token=<%= (iparam.api_key) %>","Content-Type": "application/json"};
     var options = {headers:headers};
     var url = domain+"/api/leads/filters";
         var my_lead_list = JSON.parse(data.response);
         var view_id = my_lead_list.filters[0].id; 
         var lead_url = domain+"/api/leads/view/"+view_id;
            var leads = JSON.parse(data.response);
            leads = leads.leads;
        console.error('Error occurred while retrieving lead details: ', error);

Hi @Surendar_N,

var headers = {“Authorization”: “Token token=<%= (iparam.api_key) %>”,“Content-Type”: “application/json”};

Can you please try passing the api_key by removing the () around iparam.api_key?
Hope this helps!!