Get Organizations API: "?" in query string is alterd to "%3F"

I’m trying to use Get Organizations API .

const productAuthHeader = {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'X-Force-Accept-Language': 'true',
    'Accept-Language': 'en'
}

const getOrganizations2 = async(serviceDeskId, data) => {
    let url = `/rest/servicedeskapi/servicedesk/${serviceDeskId}/organization?`;
    Object.keys(data).map(key => {
        url = url + key + "=" + data[key] + "&"
    });
    console.log(url);
    const res = await api.asUser().requestJira(route`${url}`, {
        headers: productAuthHeader,
    });

But it results in an error below.

rest/servicedeskapi/servicedesk/<MYPJ>/organization?accountId=<myID>&

"OAuth 2.0 is not enabled for method: GET /rest/servicedeskapi/servicedesk/<MYPJ>/organization%3FaccountId=<myID>&"

The url value passed to console.log is correct.
But it is altered after it is passed to requestJira().
It seems that “?” is converted to “%3F”.

Why?

I’ll consult the team that’s working on the api but this can be fixed by replacing

route`${url}`

with

route(url)
1 Like

Another approach is to use URLSearchParams

Appending of & is handled for you.

At the end use

route`/rest/servicedeskapi/servicedesk/${serviceDeskId}/organization?${searchParams}`

I tried route(url), and it worked.
Thanks!!

Hi Ara,

Using the template literal as you have will result in anything in the placeholder values being escaped, which in this case is the entire path.

Joshua’s suggestion of using URLSearchParams is the best way forward here. Nothing in route(url) will be escaped, and any special characters that occur in keys, values, etc. might result in not getting the URL you want.

2 Likes

I’m sorry to reply late.
I’ll use searchParams instead of template literal.
Thanks!