How to Access JSM Assets API from Forge Back-End Functions

Dear community,
I’ve tried multiple ways to access JSM Assets from a Web Trigger (and Scheduled Jobs modules) using requestJira, but it’s not working as expected. On the other hand, direct access via fetch works fine.

Here’s what I’ve tried (and it is not working):

const response = await api.asUser().requestJira(`https://api.atlassian.com/jsm/assets/workspace/WORKSPACE_ID/v1/object/36`, {
    headers: { 
        'Accept': 'application/json',
        'Authorization': 'Basic TOKEN'
    },
});

As well as:

  1. The same with “api.asApp()”
  2. The same with "api.asApp().requestJira(route/jsm/assets/workspace/WORKSPACE_ID/v1/object/36);
  3. The same with " - read:cmdb-object:jira" permission and a few others

The only method that works reliably is using fetch:

const response = await fetch('https://api.atlassian.com/jsm/assets/workspace/WORKSPACE_ID/v1/object/36',
    {
        headers: {
            'Accept': 'application/json',
            'Authorization': 'Basic TOKEN'
        },
    }
);

Unfortunately, I can’t rely on fetch because Forge imposes a limit of 100 requests, and any additional requests are skipped. requestJira doesn’t have this limitation, but I can’t seem to get it to work.

Does anyone have advice on how to resolve this? Any help would be greatly appreciated!

2 Likes

Hi @WilliamDBibby,
for Forge apps please use OAuth in order to access Asset APIs, not basic token-auth.

You can also refer to our documentation as to which OAuth scope is required e.g https://developer.atlassian.com/cloud/assets/rest/api-group-importsource/#api-importsource-importsourceid-schema-and-mapping-get

Hope that helps!
Cheers,
Doro

Hi @DorotheaLinneweber
Thank you for your advice. Unfortunately, as I mentioned, this doesn’t work either. Here is an example of how I tried:

const response = await api.asUser().requestJira(route`/jsm/assets/workspace/WORKSPACE_ID/v1/object/36`, {
    headers: { 
        'Accept': 'application/json',
    },
});

Could you provide a working example of how to retrieve Asset objects from the Froge back-end function using requestJira?

Hi @WilliamDBibby

Can you share some more details on what is not working to help us troubleshoot your issue? What errors or response do you get from the requestJira call in this circumstance?

I am not William but the error I get when using requestJira is 401 Unauthorized, whereas fetch() with Basic Authentication works fine.