Requests.json: Error Substituting Template - When Context Includes "

Hello there,

I encountered that when I am supplying a context variable with a value that includes an " it throws an error: “error while substituting templates.”

This is my request definition.

"jiraGet": {
    "schema": {
        "method": "GET",
        "host": "<%= iparam.jiraBaseUrl %>",
        "path": "<%= context.path %>",
        "headers": {
            "Authorization": "Basic <%= encode(context.token) %>"
        },
        "query": {
            "jql": "<%= context.jql %>"
        }
    }
}

When I call it with jql value:
"Freshdesk TicketId[Number]"=${this.ticket.id}
It fails on said error.
While this is fine:
cf[11111]=${this.ticket.id}
The only difference are the ". I tried it multiple times with and without the ", and tried escaping the characters, but nothing worked except removing the ".

This could be a potential issue for requests which need " around a value with spaces.

Thanks

W.

Hey @Wesely,

Thanks for reporting this.

When using query parameters with Request Method,

"query": {
      "key": "value"
}

This expects the value to be a string that would be URL encoded and also wanted to understand what your HTTP endpoint for this API would look like, can you share a CURL command with your endpoint credentials masked?

Hello @zach_jones_noel,

thanks for getting back to me. In the curl command it is encoded into
curl --location --globoff ‘https://test.atlassian.net/rest/api/3/search?startAt=1&jql=“Freshdesk%20TicketId[Number]”%3D12345’ \

The editor seems to decode it but the " are %22 in reality -_-

It didn’t occur to me at all since anywhere in code or in postman I don’t have to worry about it.

Also food for thought, the encoding could be handled by the client (or whatever substitutes the values), handling it in code seems cumbersome.

Thanks again

W.

Hey @Wesely,

Also food for thought, the encoding could be handled by the client (or whatever substitutes the values), handling it in code seems cumbersome.

URL encoding is taken care of by the platform. But in this case, I see multiple special characters and also quotes, so did you try something like this -

encodeURIComponent('"Freshdesk TicketId[Number]"=12345')

Hey @Wesely,

Thanks for bringing this to our notice, we have identified a bug and our engineering team is looking into it. Will keep you posted.

Hey @zach_jones_noel!
Any updates on this bug?

Hey @Nasir_Haidari,

The engineering team has their eyes on it. Will keep you posted as and when I get updates. :slight_smile:

1 Like

HI @zach_jones_noel

Do we have a workaround for this issue?

Hey @Ansfs91,

At the moment, using the query parameter value within encodeURI() should be a way to address it. Let me know if there are any challenges with that.

Hey @Wesely,

Could you try the following?

    let ticketId = 1111
    options = {
      context: {
        jql: `'Freshdesk TicketId[Number]=' ${ticketId}`,
        token: "token value"
      }
    }

   let response = await client.request.invokeTemplate("jiraGet", options);

cc @Nadeem_Bhati

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