Jira Cloud REST API and defining query parameters

Hello everyone, for the needs of my project I am using this REST API call
/rest/api/3/group/bulk?startAt=0&maxResults=3

where I want to extract the groups, but the query parameters should not be specifically defined in the API as startAt=0, but instead the startAt should receive a variable as a paramеter? Is this possible and if yes, how?

@Ivana1,

You won’t find any capabilities at the REST API level. HTTP doesn’t really know what’s in your parameters and variables. However, there is a standard that works well across languages called URI Templates.

In JavaScript, I like URI.js for this. As example:

var template = new URITemplate("https://example.atlassian.net/rest/api/3/group/bulk?startAt={start}&maxResults={max}");
var result = template.expand({start: 0, max: 3});
result === "https://example.atlassian.net/rest/api/3/group/bulk?startAt=0&maxResults=3";

And there are multiple multiple ways to express parameters, like {?startAt,maxResults}.

More than just for “parameterization”, I prefer the use of URI libraries and especially URI templates to avoid a whole class of problems that come from URL construction based on string concatenation. If not preventing, then troubleshooting is certainly easier.

Thank you for the response. I have another concern, if I want to fetch('https://example.atlassian.net/rest/api/3/group/member?groupname={groupName}, but I want the groupName to be fetched from another json file that contains all the group names one by one? How can I achieve this?

@Ivana1,

Generally, template expand is just an object where the keys match the URL template parameters, and the values can be anything that will fit the parameter constraints. So you can use whatever values you want in the expand.

A specific answer depends on the structure of the JSON. If the structure is an array of objects, maybe just for loop over them to find the one you want? If the structure is more complicated, there are all kinds of JSON query libraries.