Using DataAPI for serverless app

Hello,

I want to use some DataAPI (Data API) in server.js of the serverless app, such as something equivalent to client.data.get("loggedInUser"). I don’t want to pass the information from the front-end. Is there any way to do that other than calling an API through an API Key (Freshdesk)?

Thank you.
Nhat Nguyen

No, you cannot get loggedIn User information in any of the serverless handlers.

1 Like

Hello @Nhat_Nguyen.

Could you help us understand the use-case a little better? When you say “server.js”, are you considering having this information (the logged-in user) available for a method that handles a Server Method Invocation (SMI) or an event (Product Event perhaps)?

As @ManiDeepak_Vandrangi suggested above, in either case you will not have this information available. But perhaps understanding your use-case better may help us suggest a workaround?

Hello,
I want to use it in SMI to call an external API, however, if there is no other option, I’ll think I’ll get it though API Key or through the front-end.

Thank you

If you are using it in SMI, I am sure you are making the app work in one of the ticket locations (sidebar, full page etc)

If that’s the case, you will be able to get the logged-in user from Data API. Get that and pass it on to the SMI method that’s defined in your server.js

`app.js`
client.data.get('loggedInUser', ({ loggedInUserf }) => {
    client.request.invoke('sampleSMI', { loggedInUser }).then(resolve, reject);
})

`server.js`

exports = {
  sampleSMI: ({ loggedInUser, iparams }) => {
    // Make the necessary API calls with  logged in user
  }
}

I hope this is what you mean when saying you need to pass loggedInUser to make an API call in server.js.

3 Likes

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