Hi @BenPierce ,
Welcome to the Atlassian Developer Community.
The error message you are receiving is misleading. route
is a tagged template function and it treats constant strings differently from ${}
expressions. This is similar to the problem discussed here.
Here is some code to help you through this:
import api, { route } from '@forge/api';
async function fetchUserGroupsFromAPIAsUser(accountId) {
console.log(`Getting groups for account ${accountId}...`)
const payload = await api.asUser().requestJira(route`/rest/api/3/user/groups?accountId=${accountId}`);
const json = await payload.json();
console.log(`json = ${JSON.stringify(json, null, 2)}`);
return (json) ? json : [];
}
exports.handleEvent = async (event, context) => {
console.log(event, context);
const accountId = event.atlassianId;
const groups = await fetchUserGroupsFromAPIAsUser(accountId);
console.log(`Groups = ${JSON.stringify(groups)}`);
return {
hello: "world"
};
};
Regards,
Dugald