Hi community,
I’m using Forge app to query some Jira Cloud REST API. Can we encode the parameters when calling Jira Cloud REST API?
I tried to use encodeURIComponent encodeURIComponent() - JavaScript | MDN but the response data is not correct comparing with the parameters not encode
Thanks in advance!
Hi @Thanhbosua .
Yes you can encode URI components. The way to do this in Forge is using the route
tagged template function explained here which does the encoding for you. Here is an example
const fetchCommentsForIssue = async (issueIdOrKey) => {
const res = await api
.asUser()
.requestJira(route`/rest/api/3/issue/${issueIdOrKey}/comment`);
const data = await res.json();
return data.comments;
};
Regards,
Dugald
2 Likes
Thank you so much @dmorrow !
I tried and it worked however I found a performance issue with this approach. I tested many times API call (‘/rest/api/2/search’):
- without encoding and it took around nearly 2 seconds
- with encoding and it took around 5-6 seconds
Is it true that using the route
tagged template function will consume more time than normal?
Thanks again!