Api_key template replacement does not work (400)

Hi

The template replacement code does not work for our custom app.
The options are used when using client.request.get.

let options = {
    headers: {
      Authorization: "Basic <%= encode(iparam.api_key) %>", 
      'Content-Type': 'application/json'
    }
  };

let pagedRequestURL = ... // url with some GET query params to paginate etc.
let data = await client.request.get(pagedRequestURL, options)

Response:

Error while substituting the templates"
  status: 400
  errorSource: "APP"

We would appreciate your insights on what we’re missing.

From fdk.log when testing with dev=true with some values replaced:

2022-12-13 13:16:35.876 +0100 [debug] (e[34mdata-util.jse[0m) e[31mRead {"our_app_as_101_101_freshservice":{"our_app_as_101_101_custom_iparams":{"__meta":{"secure":["apiKey"]},"domainName":"our-freshservice-instance","apiKey":"abc123abc","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}}}}e[0m
2022-12-13 13:16:35.879 +0100 [debug] (e[34mdata-util.jse[0m) e[31mRead {"our_app_as_101_101_freshservice":{"our_app_as_101_101_custom_iparams":{"__meta":{"secure":["apiKey"]},"domainName":"our-freshservice-instance","apiKey":"abc123abc","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}}}}e[0m
2022-12-13 13:16:35.880 +0100 [debug] (e[34miframe.jse[0m) e[31mResponding to product with {"configs":{"domainName":"our-freshservice-instance","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}},"displayName":"our-app-moniker","product":{"freshservice":{"location":{"ticket_sidebar":{"url":"agent/index.html","icon":"agent/styles/images/icon.svg"}}}},"features":["db"],"actions":false,"omni":false,"products":["freshservice"],"platform":"2.2","v2":[{"id":1,"version_id":1,"configs":{"domainName":"our-freshservice-instance","apiKey":"abc123abc","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}},"displayName":"our-app-moniker","placeholders":{"ticket_sidebar":{"url":"http://localhost:10001/iframe/index.html","icon":"styles/images/icon.svg"}}}]}e[0m
2022-12-13 13:16:37.247 +0100 [debug] (e[34mdata-util.jse[0m) e[31mRead {"our_app_as_101_101_freshservice":{"our_app_as_101_101_custom_iparams":{"__meta":{"secure":["apiKey"]},"domainName":"our-freshservice-instance","apiKey":"abc123abc","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}}}}e[0m
2022-12-13 13:16:37.248 +0100 [debug] (e[34mdata-util.jse[0m) e[31mRead {"our_app_as_101_101_freshservice":{"our_app_as_101_101_custom_iparams":{"__meta":{"secure":["apiKey"]},"domainName":"our-freshservice-instance","apiKey":"abc123abc","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}}}}e[0m
2022-12-13 13:16:37.248 +0100 [debug] (e[34miframe.jse[0m) e[31mResponding to product with {"configs":{"domainName":"our-freshservice-instance","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}},"displayName":"our-app-moniker","product":{"freshservice":{"location":{"ticket_sidebar":{"url":"agent/index.html","icon":"agent/styles/images/icon.svg"}}}},"features":["db"],"actions":false,"omni":false,"products":["freshservice"],"platform":"2.2","v2":[{"id":1,"version_id":1,"configs":{"domainName":"our-freshservice-instance","apiKey":"abc123abc","$domainName":{"url":"https://our-freshservice-instance.freshservice.com","name":"freshservice"}},"displayName":"our-app-moniker","placeholders":{"ticket_sidebar":{"url":"http://localhost:10001/iframe/index.html","icon":"styles/images/icon.svg"}}}]}e[0m
2022-12-13 13:16:37.310 +0100 [debug] (e[34miframe.jse[0m) e[31mResponding with contents of /index.htmle[0m
2022-12-13 13:16:37.360 +0100 [debug] (e[34miframe.jse[0m) e[31mResponding with contents of /scripts/app.jse[0m
2022-12-13 13:16:37.361 +0100 [debug] (e[34mcoverage-util.jse[0m) e[31mInstrumenting /Users/cardboard/projects/com.freshservice.our-freshservice-instance/our-app-moniker/app/scripts/app.jse[0m
2022-12-13 13:16:39.801 +0100 [debug] (e[34mcoverage-util.jse[0m) e[31mWriting coverage.e[0m
2022-12-13 13:16:41.463 +0100 [debug] (e[34mcoverage-util.jse[0m) e[31mWriting coverage.e[0m

Hi @Bram

Once after seeing the FDK log, the key that was mentioned in your code was api_key. but in the FDK log, I could find that key name as apiKey. can you please check your iframe.json file? and please check your key name. If your key name is apiKey then you need to do like this "Basic <%= encode(iparam.apiKey) %>"

Below one is the sample object, To access the API secret value you need to do it like this "Basic <%= encode(iparam.api_secret) %>".

"api_secret": {
    "display_name": "API Secret",
    "description": "Please enter the API secret",
    "type": "text",
    "secure": true,
    "required": true
  },

If you still face the issue please share the iframe.json file.

Hope it helps

Thanks

1 Like

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