Request templates Issue

Hi Team,

I try to implement the requests template functionality in a custom application (serverless application), but I facing an Unauthorized issue (401).

can anyone help me to sort out this issue.

Issue screenshot:

./config/requests.json

{
    "getTickets": {
        "schema": {
            "method": "GET",
            "host": "<%= iparam.domain %>.freshdesk.com",
            "path": "/api/v2/tickets",
            "headers": {
                "Authorization": "Basic <%= encode(iparam.apikey) %>",
                "Content-Type": "application/json"
            }
        },
        "options": {
            "retryDelay": 1000
        }
    }
}

Iparams.json

{
    "apikey": {
        "display_name": "API key",
        "description": "Please enter your account’s API key",
        "type": "text",
        "data-bind": "product.api_key",
        "required": true
    },
    "domain": {
        "display_name": "Product Domain",
        "description": "Please enter your account’s Domain",
        "type": "text",
        "data-bind": "product.domain",
        "required": true
    }
}

manifest.json

{
  "platform-version": "2.3",
  "product": {
    "freshdesk": {
      "events": {
        "onTicketCreate": {
          "handler": "onTicketCreateHandler"
        }
      },
      "requests": {
        "getTickets": {}
      }
    }
  },
  "engines": {
    "node": "14.21.1",
    "fdk": "8.6.7"
  }
}

Hi @hemakumar,

The authorization is failing because of the substitution of the subdomain of your Freshdesk account where the template "host": "<%= iparam.domain %>.freshdesk.com" expects the value to be a string whereas your iparams configuration uses domain with a text type and "data-bind": "product.domain", this results in the value being the URL of your account.

You could change the iparam as below -

    "domain": {
        "display_name": "Product Domain",
        "description": "Please enter your account’s Domain",
        "type": "domain",
        "data-bind": "product.domain",
        "required": true
    }

Note: We don’t recommend using iparam value as a URL directly substituted in the Request template. Because you would have to break the URL into host/method/path.

Hi @zach_jones_noel,

thanks for the quick response, that issue is fixed.

1 Like