Reading/creating data from serverless app

This sample app:
Uses needle to create requests to the Freshdesk api itself.

  1. Is this the only way to access the “backend”? If I want to get the company of a contact, do I need to do that through an actual http(s) call?
  2. It also uses $db. Is that also access to the backend?
  3. why needle? Is that better/easier than the request-api?

I’m looking for a way to get some extra data (like the company of a contact) inside a serverless app to be able to also use that data (in comparison/rules/requests)
And I’m looking for a way to create a ticket from inside that same app when something goes wrong.

1 Like

Niek, May I have more details about what you refer as “Backend” ? Here are the answers that I have from what I understood.

  1. Are you here talking about the app’s backend making calls to consume Freshdesk REST APIs; Is it only possible through HTTP(S) calls? Yes. However, I’d be curious to know what other ways you’d prefer to.
  2. If you are asking does App’s backed have access to db, Answer: Yes.
  3. I hope this entirely is dependant on Developer’s preference. In a way, Needle is just bit lighter and fits enough.
1 Like
  1. an http call in this case would mean some overhead which I would deem unnecessary since the code is already running on the server. So I’m looking for a simple way to “getCompanyById” or “getContactById”. The ticket $db call seems to update the ticket “directly” with a database call (wrapper)

Like stated, in the server.js onContactUpdate I would like to do a “getCompanyById” to lookup the Company the Contact is related to. Some fields are stored redundantly in both Company and Contact. These fields may not be changed in the Contact page. Apparently there is no way to disable those fields at this moment so I’m looking for a way to detect these changes by comparing them to the Company data.

@Niek_Knijnenburg I am reiterating what I understand from the use case that you 've shared.

There are certain fields related to Contact & Companies which are stored redundantly (An example would help me understand better). You are building an serverless app either in contact_sidebar or contact_list_background. Among those fields some may not be changed in Contact page. This app’s specific case, checks whether a Contact who is related to a specific Company share the same data in the fields. If there’s a mismatch, app creates a ticket.

Did I understand your use case correct? Correct me if I am wrong.

Problem #1:

To perform this check: Contact vs Company details; Additional API calls are unnecesary as product is already running it’s code. Is there any efficient way of doing this?

To my knowledge, App runs on a different platform from away from the product itself. Today, if you need Company details onContactUpdate. You have to make an API call to the product by using to make call to this endpoint. Then perform operations to achieve the required check.

However, I will try if there is simpler way of doing this after you help me in confirming my understanding of your problem is correct.

Problem #2:

Can you help in elaborating this part more? Were the docs seem to say $db can make changes(update) to ticket properties directly?

  1. OK if this is necessary, I’ll create a helper.js with the calls I need like the sample app does.
    (btw serverless apps don’t have a location like background/sidebar right? It will be onConcactUpdate. And sending a into a company endpoint might result in unexpected behaviour :slight_smile: I would suggest contact.company_id or contact.other_companies[y].id)
  2. I have no idea what $db is/does or where the documentation is to be found. I’m just reading that piece of code. My javascript knowledge is fairly new :slight_smile:

Thanks for patiently explaining your perceptions about how these features work with your app, Niek.

Let me clarify a few things for you, based on what I believe you are trying to do.

  • Serverless apps run completely within our serverless platform, and have no relation to a browser. They generally react to change events generated from the Freshdesk back-end (when the app is a Freshdesk app) and execute your app in response. Serverless apps are therefore unrelated to any browser location.
  • The serverless app runs in an isolated environment, and does not have direct access to the Freshdesk back-end. If the event payload is missing some information your app requires, the only way to fetch that is to make a REST API call to Freshdesk. This is what the sample app you have referenced also does today.
  • $db is a platform feature that exposes a key-value store to your app. It does not give you access to the Freshdesk backend, as noted above. For more details, you can refer to Data Storage.

Finally, I would like to confirm if you are trying to compare properties between a Contact and a Company to find differences, you should be aware that there is a very tiny chance that the Company has been updated after the Contact was updated and before your app executes in response to the onContactUpdate event. Hopefully this does not affect your business use-case. If it does, let us know, and we can help you with your approach.