Problem when making requests to Freshdesk Account

I am trying to make requests with my custom app in my Freshdesk account but it doesn’t let me. I don’t know where does the problem come from.


Hey @Mariam_Akif,

Welcome to the Freshworks Developer Community! :tada:

When using Freshdesk APIs, authentication uses basic authentication. And you would have to encode "APIKEY:X" into base-64. And the headers would have to be used as -

headers: { 
    'Authorization': 'Basic <here goes the base-64 encoded APIkey:X>'
}

Learn more about it from Freshdesk API docs.

Hi Jones,
I don’t know if I have written it in the right way(i am still a beginner) but I have tried and this time I have received no response.

I have also been reading the documentation but it only mentions the option.It does not explain how.

Hi @Mariam_Akif ,

You can try the below
headers: { "Authorization": "Basic " + btoa(api + ':x'), "Content-Type": "application/json" }

But i prefer to use "Basic <%= encode(iparam.apiKey) %>" which will be must easier.

Hope this helps you.

Thanks,

1 Like

Hi Janani,
I have tried both ways but still don’t work. In the first option i don’t recevie any response and in the second one I receive a 401 error.


I’ve made the request in Postman to check if the apikey was well written and it worked well with the basic auth.

@Janani mentioned the right way to encode it. Thanks, Janani. :raised_hands:

@Mariam_Akif,
<%= iparam.f_apikey %> would be applicable only when you are using Freshworks Developer Docs | Freshworks app ecosystem but you are using axios and in the serverless component of the custom app, you can get the iparam values from the invoking event.

onTicketCreateCallback: function(payload) {
       let apiKey = payload.iparams.f_apikey;    
}

I have tried again but I still don’t receive any response. However with the following option I receive de error 401:


Again, this is in Axios and not in Request Method so you would have to use btoa() itself for encoding to base-64 instead of encode().

Below snippet would work, note the snippet is using onTicketCreateCallback as the event handler function.

onTicketCreateCallback: function(payload) {
       let apiKey = payload.iparams.f_apikey; 
       let URL = "......"
       let options = {
                headers: {
                            "Content-type": "application/json",
                            "Authorization": "Basic " + btoa(apiKey + ":X")
                }
       }
       let response = await axios.get(URL, options)
}

Alternative to btoa() you could use Buffer with the same snippet replace btoa() function with -
Buffer.from(apiKey + ":X").toString('base64')

I don’t receive no information about the response. I wanted to try with the Request Method but i had problems when creating the request.json file.
image

Hi @Mariam_Akif ,

Kindly refer to the requests.json and App.js for reference.

Regards,
Thakur

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.