Requesting field config results in INVALID_TARGET_URL error

Hello,
I’m running into a problem trying to get configuration of a custom field. Requests fail on this bit of code:

const fieldId = "customfield_10051";
const config = await api.asApp().requestJira(
  route`/rest/api/3/app/field/${fieldId}/context/configuration`,
  {
    headers: {
      Accept: "application/json",
    },
  },
);

And this is the error I get in the tunnel console:

ERROR   12:23:19.165  e9019845-5d46-4550-bd1a-f9857bcc50e0  Error in handler getFieldConfig PROXY_ERR: Forge platform failed to process runtime HTTP request - 400 - INVALID_TARGET_URL
    at handleProxyResponseErrors (webpack:///node_modules/.pnpm/@forge+api@3.8.0_@swc+core@1.4.1/node_modules/@forge/api/out/api/fetch.js:84:1)
    at <anonymous> (webpack:///node_modules/.pnpm/@forge+api@3.8.0_@swc+core@1.4.1/node_modules/@forge/api/out/api/fetch.js:29:1)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 400,
  errorCode: 'INVALID_TARGET_URL'
}

It’s notable that just entering the URL from the request into a browser returns the configuration just fine.
The error seems similar to the one discussed here: Proxy error in development and staging when calling Confluence attachments API with requestConfluence
Could I get some assitance, please?

Hi @ViktorWolf1, are you able to provide us with your appId?

Hi, our appId is: ari:cloud:ecosystem::app/c6e2b50d-017f-47fa-818d-52cfb113da35

Hi @ViktorWolf1, thank you for providing your appId. I wasn’t able to reproduce the error using the code snippet you provided.
I had a look at the logs for your app, this particular error case that you are running into occurs when the base URL of the request is overridden to something that is not valid, for example: if the route passed into the request was a full URL like https://exampleurl.com or if it is something like ../upOneLevel. Are you able to confirm that something like this is not happening for your app?

2 Likes

OK, I have figured it out. When I posted the code here, I changed the formatting, which inadvertently ended up masking the cause of the issue - the actual code had the string template on a new line, so it had the newline character (\n) at its beginning.

I have no idea how I missed that in the first place, and somehow it didn’t occur to me to just log the resulting route before reading your post, so thanks for pointing me in the right direction. I’m sorry for bothering you with such a silly mistake.

1 Like

No worries @ViktorWolf1, I am glad to hear that it is now working for you!