onAppInstall function doesn't save data on Data Storage

Hello everyone.

I’m building an app for Freshservice that uses dynamic parameters to get the generated URL from serverless.

Here is an example of onInstall code that generates the URL and save it in Data Storage:
algar001

Here I’m using the dynamic parameters to get the URL from Data Storage and put it on webhook field in iparams:

But I’m facing an error here. The data isn’t been returned to the field and I’m receiving an error saying that this data wasn’t found:

There is a console.log on onAppInstall function that I can know if the URL has been generated and saved in Data Storage. But I also can’t see the serverless logs:

PS: I use the same code in a Freshdesk app, and it works fine.

PS2: This issue occurs when I install my app on customer’s account.

Did everyone else face this issue? If so, how could you solve it?

Thank you!

Can you confirm if this data is being accessed within the application other than installation screen?
If yes, then try to use SMI to get this data in installation screen.

Hey @yusrakhatri

I’ll make this test and let you know ASAP.

Thank you.

1 Like

Hello @yusrakhatri

I’ve tried your suggestion and it didn’t work.

Actually it seems like generateTargetUrl() function doesn’t work on Freshservice. I say it because I made an example here. I just tried to get the URL and send to Request Bin, but I don’t receive any response there:

onAppInstallHandler: function(payload) {
    console.log('DADOS DA INSTALAÇÃO >>> ', payload);
    generateTargetUrl().then(function(url) {
      unirest.post('https://enpc3jwe5rnxnjg.m.pipedream.net')
      .headers({
        'Content-Type': 'application/json'
      })
      .send(JSON.stringify({url: url}))
      .end(function(res) {
           console.log(res.body);
           renderData();
      });
    }).fail(function(err) {
      console.log('ERRO AO GERAR URL >>> ', err);
    });
}

This code works fine locally but it doesn’t work when I install it in production.

Thank you!

2 Likes

@omarcelo, Thanks for checking this. I will try to reproduce the issue and work with app platform or Freshservice team to understand if needed to post my learnings on this thread.

Hey @Saif

It would be nice if you can share your thoughts here.

Thank you for helping us!

Hi @omarcelo,
Data storage won’t work until the app is installed successfully.

I doubt this will work. Can you please check again to see if it is working in Freshdesk? Also, did the same snippet worked locally?

Can you please try the below snippet in your Freshservice account and share the logs so we can debug the issue

onAppInstallHandler: function(payload) {
  console.log('DADOS DA INSTALAÇÃO >>> ', payload);
  generateTargetUrl().then(function (url) {
    unirest.post('https://enpc3jwe5rnxnjg.m.pipedream.net')
      .headers({
        'Content-Type': 'application/json'
      })
      .send(JSON.stringify({ url: url }))
      .end(function (res) {
        console.log(res.body);
        renderData();
      });
  }).fail(function (err) {
    console.log('ERRO AO GERAR URL >>> ', err);
    renderData();
  });
}

Hello @ManiDeepak_Vandrangi

Yes, it works fine in my Freshdesk app. I’m using it in our published app on Marketplace:

And I’ve tried your code and it didn’t work as well.

There is another point here. I’ve read the serverless logs and it returns the following log:

It seems like the app isn’t intalled on the account and it is so weird.

Please let me know if you want me to do more tests.

Thank you.

Hi @omarcelo,
We found new points by debugging this topic

  1. In frontend iparams page, the app cannot access data storage
  2. In backend app install handler, data storage feature can be used.
  3. Until the app install handler’s execution is done, the app is not considered as installed since the installation will be cancelled if renderData returned error.

Hope these points help you in debugging the issue.

Adding to my previous message, I had tried the following snippet which had stored the webhook ( this data cannot be accessed from the installation params page )

  onAppInstallHandler: function(payload) {
    console.log('DADOS DA INSTALAÇÃO >>> ', payload);
    generateTargetUrl().then(function(url) {
      $db.set('webhook', {'url': url}).then(function(data) {
        if(data.Created) {
          console.log('GRAVOU NO DATASTORAGE!!!');
          renderData();
        }
      }, function(err) {
        console.log('NÃO FOI POSSÍVEL SALVAR A URL DE WEBHOOK >>> ', err);
        renderData();
      });
    }).fail(function(err) {
      console.log('ERRO AO GERAR URL >>> ', err);
      renderData();
    });
  }

One of the app logs

    {
        "appDetails": "",
        "categoryName": "appEvent_onAppInstall",
        "logSource": "APP",
        "RequestId": "",
        "type": "info",
        "message": "GRAVOU NO DATASTORAGE!!!"
    }
2 Likes

@ManiDeepak_Vandrangi

I’ve made some tests here. I could generate, save and get the URL but I had to create a serverless app (I was trying to do it on a hybrid app, with front and back-end).

Like I said, it works fine on a hybrid app for Freshdesk. If you can make some tests on these conditions it would be nice.

Otherwise I think we can close this topic for now.

Thank you so much for your help.

@omarcelo
We had debugged this issue and found the root cause. The fix is going to take some time and we cannot give any ETA.