JSM Forge app: Get list of organizations for a customer

I have added a portalHeader to a JSM project and have added an invoke call back to a resolver.

In the resolver, I call the following to try and get a list of the Organizations for the customer.

// Get the list of organizations associated with a customer 
const fetchOrganizationsForUser = async (serviceDeskId, accountId) => {
  console.log(`fetchOrganizationsForUser(serviceDeskId=${serviceDeskId}, accountId=${accountId})`);

  // Get the organizations in the instance
  try {
    // Fetch organization details using the Jira Service Management API
    const searchParams = new URLSearchParams({ accountId: accountId });
    const url = `/rest/servicedeskapi/servicedesk/${serviceDeskId}/organization?${searchParams}`;
    console.log(url);
    const response = await api.asApp().requestJira(route(url));

    if (!response.ok) {
      throw new Error(`Failed to fetch organizations for user. Details: ${response.status}`);
    }

    const data = await response.json();
    return data.values;

  } catch (error) {
    console.error('Error fetching organization for user:', error);
    return(null);
  }
}

The manifest looks a bit like this:

  jiraServiceManagement:portalHeader:
    - key: add-customer-to-asset-portal-header
      resource: header
      resolver:
        function: resolver
      render: native
      unlicensedAccess: 
        - unlicensed
        - anonymous
        - customer

... removed for clarity ...

permissions:
  scopes: 
    - manage:servicedesk-customer

I am getting a 401 no matter if I try asApp or AsUser.

How do I resolve this?

1 Like

For the lack of anything else to try, I recreated the application by running forge create again and copied the code into the new app skeleton.

After a forge deploy and forge install the app works as expected.

With the previous app, I only introduced the unlicensedAccess settings later in the development.

Is it possible that the permission scopes / unlicensedAccess settings were not updated correctly when doing forge deploys as these settings were added to the manifest as I experimented?

We are also having this problem with unlicensedAccess seemingly not working as expected for an app we already have in the Marketplace.

Obviously, we are unable to just forge create another app because this would abandon the existing users.

1 Like

Have you been running the tunnel during those experiments? Changes to the manifest are not picked up automatically, i.e. you need to stop the tunnel and run an explicit forge deploy - users keep stumbiling over this (incl. myself), so definitely room for DX improvements there.

1 Like

Thanks for the suggestion, but during this process, we stopped the tunnel, and ran forge deploy, forge install --upgrade, forge tunnel many times.

When time allows, we will do more testing to see if we can recreate the behaviour.

1 Like