Freshdesk SDK Client Not Present in iparams.html

Hi Team,

We are currently updating an existing marketplace app and need to integrate a function that calls the Freshdesk API using the Freshdesk SDK client. However, we’ve encountered an issue where the client object from the Freshdesk SDK doesn’t seem to be available in iparams.html, even though its script has been added.

Here’s the code snippet for reference:

<script type="text/javascript">
window.freshdeskGetRequest = async (endpoint) => {
    if (client && endpoint) {
        const resp = await client.request.invokeTemplate(endpoint, {
            context: {},
        });
        return resp;
    } else return null;
};
</script>

<script src="{{{appclient}}}"></script>

For context, the Freshdesk platform version we are using is 2.3, and the app’s manifest.json file is as follows:

{
  "platform-version": "2.3",
  "product": {
    "freshdesk": {
      "events": {
        "onConversationCreate": {
          "handler": "onConversationCreateHandler"
        },
        "onAppInstall": {
          "handler": "onAppInstallHandler"
        },
        "onAppUninstall": {
          "handler": "onAppUninstallHandler"
        }
      },
      "requests": {
        "onConversationCreate": {},
        "onAppInstall": {},
        "onAppUninstall": {},
        "ticketFields": {}
      }
    }
  },
  "engines": {
    "node": "18.20.4",
    "fdk": "9.2.0"
  }
}

Could you kindly assist us with this?

@Raviraj we would greatly appreciate your help with this

Hi @eugborisov

You have to generate the client object in your iparams.html file like below

let client;
document.onreadystatechange = async () => {
  if (document.readyState === "complete") {
    client = await app.initialized();
  }
};

Don’t forget to write the above code into the script tag in your iparams.html

Thank you @Kithiyon

We were able to fix that but now we are getting 400 error while trying to invoke a template


errorSource: "APP"
headers: {}
response: "Error while substituting the templates"
status: 400

My request schema is

  "ticketFields": {
    "schema": {
      "method": "GET",
      "protocol": "https",
      "host": "<%= iparam.domain %>.freshdesk.com",
      "path": "/api/v2/ticket_fields",
      "headers": {
        "X-ACCOUNT-KEY": "<%= iparam.account_key %>",
        "Authorization": "Bearer <%= iparam.token %>",
        "Content-Type": "application/json"
      }
    }
  }

Also tried Basic authorization but that didn’t help

    "Authorization": "Basic <%= encode(iparam.token) %>",

Hi @eugborisov

Great!

I want to know where you are trying to make the above request—in your iparams.js or app.js?

If you are trying to invoke the template from iparams.js, you can’t access the iparams values in request.json. Instead, you need to send the api_key and domain as contextual data.

@Kithiyon thank you, that worked!

1 Like

I am trying to invoke the template from iparams.js, so I understand that I can’t access the iparams values directly in request.json. I will modify the code to send the api_key and domain as contextual data instead, as you suggested.

I will make this change and test the API call again.

Thanks for your help!