Getting "error while substituting templates" with non-freshworks API

I’ve been migrating my code to use the new requests method in 2.3 platform. I have a serverless app. I have been able to get $requests.invokeTemplate() to work for calls to freshsales but now I’m trying to do the same with an external web service (api-pa.mindflash.com) and I am getting the following error:

{
  status: 400,
  headers: {},
  response: 'error while substituting templates.',
  errors: {},
  errorSource: 'APP',
  attempts: 1
}

This is my entry in requests.json:

  "lmsGet": {
    "schema": {
      "method": "GET",
      "host": "api-pa.mindflash.com",
      "path": "/api/v3/group",
      "headers": {
        "Content-Type": "application/json",
        "x-mindflash-Apikey": "**********"
      }
    },
    "options": {
      "retryDelay": 1000,
      "maxAttempts": 5
    }

I invoke the requests API this way

  try {
    var res = await $request.invokeTemplate("lmsGet", {context: {path:"/group"}})
  } catch(e) {
    console.log(e)
  }
  console.log(res)

This generates error shown at top with message “error while substituting templates”.

Any suggestions on what I"m doing wrong?

Hello @freshworks team, I’m quite stuck on this. It’d be great if you had a suggestion.

Hi @stevemc,

I hope you have some template syntax for the API key mentioned in the headers. I don’t see any other template, and everything is pure text.

This error means there’s some issue with replacing a proper value for the mentioned template for installation parameters, context data, or access token.

Could you share how the structure is used if it can be shared publicly? If not, could you verify yourself if the syntax is correct and a value is available for it when the app invokes this request (for example, the iparams value is already submitted if the installation parameter is used)? In headers, all of them are accepted. There’s no restriction for headers section.

Thank you. this helped me realize my mistake.

Turns out one of the iparam values in requests.json had an “s” on end of iparam:

“x-mindflash-Apikey”: “<%= iparams.lms_api_key %>”

should be:
“x-mindflash-Apikey”: “<%= iparam.lms_api_key %>”

Works fine now. Thanks again!

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.