Unable to make API request in Serverless product event after agent level OAuth

Hello Team,
Hope you guys are doing well

We are working on a third party integration with Freshdesk and using Agent level OAuth for authentication.
On successful authentication by the agent from ticket sidebar app we are able to fetch required data from third party service provider in front end.
Our application functionality is to POST data to third party service provider when a service task is created/updated in Freshdesk. Since this has to be an instantaneous process we have used OnTicketCreate and OnTicketUpdate product event.
But using the same API endpoint as used in Front end we are not able to POST data in Serverless product event.

onTicketUpdateCallback: function (payload) {
 console.log("////// Ticket update product Event has been triggered ///////");
 console.log(`-------- ${payload.data.ticket.id} ---------`);
 var opt = {
   headers: {
     "Authorization": "bearer <%= access_token %>",
     "Accept": "application/json",
     "Content-Type": "application/json"
   },
   isOAuth: true
 };
 $request.get("https://graph.microsoft.com/v1.0/me/events?$select=subject,body,bodyPreview,organizer,attendees,start,end,location", opt).then(function (data) {
   console.log(JSON.parse(data.response));
 },function (error) {
   console.log(error);
 }): }

Kindly let me know if this is possible or is there any workaround available.
Thanks for you help
Sarfaraz

HI @sarfaraz_Mohammed,

Developers can’t invoke this onTicketUpdateCallback function. This will be called internally when our platform receives events from freshDesk.

Are you calling this onTicketUpdateCallback function from frontend using SMI? correct me if i am wrong.

Hi @Gopinath_Radhakrishn,
Thanks for you response,

As you said onTicketUpdateCallback is getting evoked when a ticket is updated in Freshdesk and i am using this callback function to update the third party service provider.
But the API request i am making fails with the following Error

{ status: 400, response: '{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: \'refresh_token }`

To answer you question i am not using SMI call in this case.

exports = {
  events: [
    { event: 'onTicketCreate', callback: 'onTicketCreateHandler' },
    { event: "onTicketUpdate", callback: "onTicketUpdateCallback" },
  ],
}

@sarfaraz_Mohammed Serverless app can only use account-level OAuth tokens. So, the app should be changed to account-level OAuth. The combination of agent-level OAuth for frontend and account-level OAuth for Serverless app is not possible.

Is there a requirement to have agent-level OAuth in your frontend app?

Hi @Raviraj,

Thanks for your reply, yes we need to have an agent-level OAuth in frontend App.
This App will be used by Freshdesk agents.
Since a part of our requirement is to make Api calls to the third-party service provider during a ticket create or ticket update. We are inclined to use the Serverless product events as a trigger point.

Hi @sarfaraz_Mohammed,

Let me find if there any other way to use the same OAuth credentials in the Serverless app as well.

If it’s not possible, any other workaround has to be incorporated to make API calls in the Serverless app with a separate authorization mechanism.

@sarfaraz_Mohammed It’s not possible to use Agent OAuth in the Serverless component of the app. It’ll work only in the frontend.

Multiple OAuth mechanism in the same app is not supported. So, when frontend app uses agent-level OAuth, Serverless app has to use any other authorization such as API key way. It’s the only possible way in this case.

Thanks for the update @Raviraj

1 Like