No response from api.asUser().requestJira

Hi,
I am trying to fetch user’s group using this api

export const getAllGroupsFromUser = async (accountId) => {
  try {
    console.log("1. Inside getAllGroupsFromUser ");

    const response = await api
      .asUser()
      .requestJira(route`/rest/api/3/user/groups?accountId=${accountId}`, {
        headers: {
          Accept: "application/json",
        },
      });
      
    console.log("2. after api call!!!!");

    const data = await response.json();
    console.log(`Response: ${response.status} ${response.statusText}`);
 
  } catch (error) {
    console.error("Could not fetch user groups: ", error);
  }
};

here, the log before api call works but after that nothing is logged. The api works fine in postman, and also similar code with different api that worked before has stopped working now.

Has there been any update in permissions that needs to be done?
Tried updating @forge/api from 2.11 to 2.18 ,reinstalling the plugin, redeploying, but nothing helps.

Can you share the part of the code where you are calling getAllGroupsFromUser? Did you make sure to await the returned promise so that the Forge function isn’t terminated before the API responds?

hi @klaussner
yes, I made sure to use await async.
This the the method which calls the above function.


const removeGroup= async (users) => {
  users.map(async (user) => {
    const  status  = await getAllGroupsFromUser(user.account_id);
    console.log("status :" + status);
  };
};

I made some changes and tried sending the response status , but get error as it no status is sent from getAllGroupsFromUser method.
Also, this function is being called from forge resolver , which also has await.

I think the problem here is the map call. You are creating an array of promises with map, but the code isn’t waiting until the promises are resolved. You can use Promise.all to create a single promise from the array of promises and wait for it:

const removeGroup = async (users) => {
  await Promise.all(users.map(...));
}
1 Like

hi @klaussner
This worked, this was an issue from my side and not forge’s.
Thank you for the solution.

1 Like