Product Event - Not Getting Triggered

Hi,
I am facing an issue in onTicketCreate and onTicketUpdate events not getting triggered in the serverless app
It working fine in local but not working in the custom app

Below is the Manifest.json file

{
  "platform-version": "2.2",
  "product": {
    "freshservice": {
      "events": {
        "onTicketCreate": {
          "handler": "onTicketCreateHandler"
        },
        "onTicketUpdate": {
          "handler": "onTicketUpdateHandler"
        },
        "onScheduledEvent": {
          "handler": "onScheduledEventHandler"
        }
      }
    }
  },
  "whitelisted-domains": [
    "https://app.lansweeper.com",
    "https://api.lansweeper.com",
    "https://cresthelpdesk.freshservice.com"
  ],
  "engines": {
    "node": "14.20.0",
    "fdk": "8.5.0"
  }
}

Below is the server.js file

exports = {
  
  
  onTicketCreateHandler: async function (payload) {
    try {
      console.info("args ", JSON.stringify(payload));

      let finalresult = [];
      let i = 0;
      let per_page = 20;
      do {
        i = i + 1;
        console.log("I ", i);
        let headers = {
          "Content-Type": "application/json",
          "Authorization": "Basic <%= encode(iparam.api_key) %>",
        };
        let url = `https://domain.freshservice.com/api/v2/products?per_page=${per_page}&page=${i}`
        console.info("url ", url);

        await $request.get(url, { headers }).then(function (data) {
          // success
          console.info("sites ", data);
          let result = JSON.parse(data.response)
          console.info("result ", result.products);

          finalresult = result.products;
          console.info("result ", finalresult.length);

        }, function (err) {
          // failure
          console.error(err);
        });
        // success

      } while (i < 551);
    } catch (ex) {
      console.log("ex ", ex)
    }
  },

  onTicketUpdateHandler: function (payload) {
    console.info("args 11 ", payload);

    let headers = {
      "Content-Type": "application/json",
      "Authorization": "Bearer <%= access_token %>"
    };
    let reqData = {
      headers: headers,
      isOAuth: true,
      body: JSON.stringify({
        "query": "{ authorizedSites { sites { id name } } }"
      })
    };
    let url = "https://api.lansweeper.com/api/v2/graphql"

    $request.post(url, reqData)
      .then(function (data) {
        // success
        console.info("sites ", data);
      }, function (err) {
        // failure
        console.error(err);
      });
  },

  onScheduledEventHandler: function (payload) {
    console.log("Logging arguments from onScheduledEvent: " + JSON.stringify(payload));
    if (payload.data.account_id = "3") {
      //your code to perform any actions
    }
  }
};

So I am not getting what is wrong in above structure?
Anybody can help

Thanks !!

I can find nothing wrong with the code you posted.

Can you try creating a new trial account and uploading the app to test there?

If the same events work in another account, there might be something wrong with the present account and we will have to involve Marketplace support.

1 Like

I have tried to upload the same app to another account

But it is still not working

Can you help!!

@DevRel-Squad Can one of you please take a look at the code here? I don’t see anything outright wrong, but I may have missed something.

@Anushka_Ahir Please allow us a while to get back. The whole team is busy with or travelling for our upcoming developer summit. :slight_smile: