Please can someone provide an example of using the $db.get method to read tickets, or other data within a "server.js" function. I am trying to perform the equivalent of
to get the identity of the Agent initiating the request.
From the documentation, it appears this information is available to event handlers, as 3 parameters are supplied (iparams, requester, and data), but invoked handlers are only provided with 2 parameters.
[Note: All requests using the $db.get method result in "Record not found" errors, and the examples provided are associated with event handling where the loggedInUser is passed into the event handler function.]
<Edited my first response, For some reason, I initially read this purely as a data storage question>
As your post already mentions, for data storage you should omit the "client" and simply use the $db.get method. However, you should have stored the required information first using $db.set, which is why you are getting the "Record not found" error. You can refer to the following sample - https://github.com/freshdesk/marketplace-sample-apps/blob/master/Freshdesk/v2/scheduled_events_sample_app/server/server.js
However, I see you are trying to get the currently logged in agent which is not automatically available for serverless apps. Could you elaborate on the app's use case? We may be able to suggest an alternate way of obtaining this information.
There are two elements of the requirement:
1. I was to restrict some of the serverless app's capability based on the role of the agent. i.e. As a administrator I can do more things than a standard agent.
2. I want to include some element of logging in the serverless app's capabilities, and I need to know the agent's name to include the details in the log.
All of these things are possible in the serverless app if it is triggered in response to an event, so why not when handling an invoke function?
When a serverless app is triggered in response to an event, the event payload is automatically passed to it.
When it is invoked from the front end (using Server method invocation), only the iparams are passed automatically. All other data can be passed using the options parameter. For your use case, you can first get the currently logged in user and then pass it as part of this options object.
Let me know if this helps, if not I'll convert this into a ticket and reach out separately.
Start your 21-day free trial. No credit card required. No strings attached.Start Free Trial