How to use requests templates with non-Freshworks web services

I’m writing a serveless app.

I need to make GET, PUT and POST requests to a non-freshworks web service. I noticed the requests templates must be defined inside of a freshworks product. But I also notice that I can define a request template outside of a product and only a warning is thrown.

Let’s say I need to call GET, PUT or POST on “mywebsvc.mycompany.com”. How do I go about doing this?

Can I use request templates for this? If not, do I need to use a non-freshworks library and does anyone have recommendations?

For example, let’s say I define this request template:

  "lmsGet": {
    "schema": {
      "method": "GET",
      "host": "api-pa.mindflash.com",
      "path": "/api/",
      "headers": {
        "Content-Type": "application/json",
        "x-mindflash-Apikey": "<%= iparams.lms_api_key %>"
      }
    },
    "options": {
      "retryDelay": 1000,
      "maxAttempts": 5
    }
  }
}

Inside manifest.json I would have this:

{
  "platform-version": "2.3",
  "product": {
    "freshworks_crm": {
      "events": {
        "onContactCreate": {"handler": "onContactCreate"},
        "onSalesAccountCreate": {"handler": "onAccountCreate"},
        "onDealCreate": {"handler": "onDealCreate"},
        "onContactUpdate": {"handler": "onContactUpdate"},
        "onSalesAccountUpdate": {"handler": "onAccountUpdate"},
        "onDealUpdate": {"handler": "onDealUpdate"}
      }
    }
  },
 "requests": {
     "lmsGet":{}
  },
  "dependencies": {
    "util": "0.12.4",
    "googleapis": "39.2.0"
  },
  "engines": {
    "node": "18.16.1",
    "fdk": "9.0.2"
  }
}

Then I invoke it with this:
$request.invokeTemplate('lmsGet', {context: {}})

This is what I get when I run fdk validate:

DataFixer> fdk validate
Please ensure that the following are addressed for quick review process:
⚠ request template 'lmsGet' is declared but not associated with any product

✔ Validation Successful

Is it valid to define request template for non-Freshdesk web services?
If I would appreciate recommendations on best practice for calling 3rd party web services from serverless apps.

You must use same name for the request template and manifest (in your code replace lmsReq by lmsGet in requests.json).

As far as I could understand, for each http method you must create a different template.

1 Like

Thanks. those were typos but my main point is about if this is the proper way to call 3rd party web services.

Hey @stevemc,

Thanks for bringing this to our notice. Ideally the request lmsGet should be inside product.freshworks_crm if not, fdk validate should error up. Can you tell me your current fdk version?

This would be the correct manifest.json

{
  "platform-version": "2.3",
  "product": {
    "freshworks_crm": {
      "events": {
        "onContactCreate": {"handler": "onContactCreate"},
        "onSalesAccountCreate": {"handler": "onAccountCreate"},
        "onDealCreate": {"handler": "onDealCreate"},
        "onContactUpdate": {"handler": "onContactUpdate"},
        "onSalesAccountUpdate": {"handler": "onAccountUpdate"},
        "onDealUpdate": {"handler": "onDealUpdate"}
      },
      "requests": {
         "lmsGet":{}
      },
    }
  },
  "dependencies": {
    "util": "0.12.4",
    "googleapis": "39.2.0"
  },
  "engines": {
    "node": "18.16.1",
    "fdk": "9.0.2"
  }
}

Curious, what is the experience when the app is invoking the template request.invokeTemplate('lmsGet',{}) ? Is there any error?

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