Error while substituting templates

Hello,

I just started working with custom Apps for Freshservice and am currently trying set up a very simple installation page with validation of the API key. To validate the key I am trying to use request methods, but no matter what I do, I get “error while substituting templates.”. Here the console output:
image

My code is as follows:

iparams.json

{
    "api_key": {
        "display_name": "API Key",
        "description": "Please enter your API key",
        "type": "api_key",
        "secure": true,
        "required": true,
        "data-bind": "product.api_key",
        "type_attributes": {
            "product": "freshservice"
        },
        "events": [
            {
                "change": "apiKeyChange"
            }
        ]
    }
}

iparams.js

app.initialized().then(
    function (_client) {
        window.client = _client;
    },
    function (error) {
        //If unsuccessful
        console.error(error);
    }
);

function apiKeyChange() {
    console.log(utils.get("api_key"));
    client.request.invokeTemplate("validateAPI").then((response) => console.log(response));
};

requests.json

{
    "validateAPI": {
        "schema": {
            "method": "GET",
            "host": "digitale-transformation-fs-sandbox.freshservice.com",
            "path": "/api/v2/tickets",
            "headers": {
                "Authorization": "Basic <%= encode(iparam.api_key) %>",
                "Content-Type": "application/json"
            }
        }
    }
}

Could someone help me with this?

Hey @chrism,
Looks like you are using validateAPI in iparams.js where the iparam values are not yet set. You would have to set the api_key via context.

{
    "validateAPI": {
        "schema": {
            "method": "GET",
            "host": "digitale-transformation-fs-sandbox.freshservice.com",
            "path": "/api/v2/tickets",
            "headers": {
                "Authorization": "Basic <%= encode(context.api_key) %>",
                "Content-Type": "application/json"
            }
        }
    }
}

You can refer to the sample app - https://github.com/freshworks-developers/request-method-samples/blob/main/sample-app/config/assets/iparams.js

Hope this helps!

1 Like

Thanks, I got it working now by changing it to using context.

1 Like

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