How to use API in FreshDesk App

Hello,
We are trying to create one custom fresh desk app. We have already gone through the first sample app successfully but now we are not able to proceed further. So we are sharing our requirements below. So please help us to proceed.
We want to create a custom app where app will call a API URL with customer id. The API will return some data based on this id and we need to display this in this app.
Please let us know how should we proceed.
Thanks!

It will be helpful if you can elaborate a bit about where you are facing an issue. Are you facing issues calling API Url in the frontend app? If so, you can look at Request Method and Freshdesk documentation.

Hello,
Please see the below code of app.js file. We are trying to implement it but our localhost url is not called. Please help us.

document.onreadystatechange = function () {
  if (document.readyState === 'interactive') renderApp();

  function renderApp() {
    var onInit = app.initialized();

    onInit.then(getClient).catch(handleErr);

    function getClient(_client) {
      window.client = _client;
      client.events.on('app.activated', onAppActivate);
    }
  }
};

function onAppActivate() {
  var textElement = document.getElementById('apptext');

  var getContact = client.request.get("http://localhost/index.php?route=account/test", { client: true });

  getContact.then(showContact).catch(handleErr);

  function showContact(payload) {
    textElement.innerHTML = `Ticket created by ${payload.contact.name}`;
  }
}

function handleErr(err) {
  console.error(`Error occured. Details:`, err);
}

Thanks!

Hi @opencartcity,

I suspect that there might be validation issues with regards to the use of localhost URL. Request method expects a FQDN and would throw an error if its a localhost URL / IP. Can you start an ngrok server that acts as an alias for the localhost URL ?

var getContact = client.request.get("https://example.com?route=account/test", {
    client: true
});
getContact.then(function(data) {
    console.log(data)
}).catch(function(err) {
    console.error(er)
});
1 Like

Hello,
Thanks for your response and it worked but we are not able to send and receive the data now. So we basically want to send the customer id based on ticket id and receive some data based on this id.
In detail, we want to achieve the work flow where we open a ticket, it calls a url with customer id of this ticket, we get the response from this url and display in app.
Thanks!

Is there any one who can help with this?