Getting 400 Error saying "Error While Substituting the templates"

Hi there,
I was trying to make a Freshdesk app. I need to get data through a REST API. I need that REST API Response to be showed in the app.js file. I have changed the Whitelisted Domains in the manifest folder as well. Some times, I am getting an error saying " The domain has not been white-listed", sometimes, I am getting “Error While Substituting the templates”. Below shows the code that I used to get the data from an API. Could you guys please help me with this?
app.js
============= Start ====================

var client;

init();

async function init() {

client = await app.initialized();

client.events.on('app.activated', renderText);

}

const dataBody = {

"Filter": {

    "OrderStatus": [

        "New",

        "Pick",

        "Pack",

        "Dispatch"

    ],

    "OutputSelector": ["OrderID", "Email"]

}

};

async function renderText() {

var url = "https://www.tools.com/do/WS/NetoAPI";

let response = await client.request.post(url, {

    headers: {

        'Accept': 'application/json',

        'NETOAPI_ACTION': 'GetOrder',

        'NETOAPI_USERNAME': 'Test_Cin7',

        'NETOAPI_KEY': ''

    },

    body: JSON.stringify(dataBody),

    isOAuth: true

});

console.log("RESPONSE DATA " + JSON.stringify(response));

}

=========== End ====================

Here is the Error Message.

Here is the Manifest.json file

Hi @Amila_Deshan

Good day and Welcome to the community.

Any URL used in your application to make API calls has to be whitelisted in manifest.json therefore please add “https://www.tools.com” as well in your whitelisted-domains list.

Hi @Amila_Deshan

It looks like a error returned from “www.tool.com” in response to your request (i.e. Invalid Request). Can you try running the request using postman or curl to see if the request is working?

@Sachin_Kumar,
Thank you for letting me know that API is showing their. This is just a testing environment. I will change those credentials after this is done. Any way, Yes I am using API Authentication as you can see in my CURL. I have removed it and tested out. This is my new code. I am getting client.request is not a function error now.

================= Start ====================
var client;

init();

async function init() {

client = await app.initialized();

client.events.on('app.activated', renderText);

}

const dataBody = {

"Filter": {

    "OrderStatus": [

        "New",

        "Pick",

        "Pack",

        "Dispatch"

    ],

    "OutputSelector": ["OrderID", "Email"]

}

};

async function renderText() {

var url = "https://www.tools.com/do/WS/NetoAPI";

let response = await client.request(url, {

    method: 'POST',

    headers: {

        'Accept': 'application/json',

        'NETOAPI_ACTION': 'GetOrder',

        'NETOAPI_USERNAME': '',

        'NETOAPI_KEY': ''

    },

    body: JSON.stringify(dataBody)

});

console.log("RESPONSE DATA " + JSON.stringify(response));

}

=================== End =====================

Here is the error Screenshot

image

Hi @Amila_Deshan

Please refer Request Method for syntax and uses. As the error indicates client.request is not a method, it should be client.request.post(url, options)

@Amila_Deshan

Also please include ‘Content-Type’: ‘application/json’ header in headers of your request.

2 Likes

Hi @Sachin_Kumar,
It worked. Thank you very much.

1 Like

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