Forge Assets Rest API Support

Hi,

I am trying to make a rest from a Forge App to use the Asset Rest APIs to create an asset using the endpoint here.

I notice that the endpoints in the Assets Rest API docs do not give any examples of interacting with these APIS from Forge.

I have tried calling the Create asset API from Forge using either asUser() or asApp() with a request like the one below, but unfortunately, this returns a 403 forbidden response.

// bodyData and base64EncodedCredentails are defined above in my code.
const response = await api.asUser().requestJira(route`/jsm/assets/workspace/${workspaceId}/v1/object/create`, {
  method: 'POST',
  headers: {
    //'Authorization': `Basic ${base64EncodedCredentials}`,
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(bodyData)
})

I have also then trying using the approach to authenticate with Jira as mentioned in the forge docs here with the code snippet in the sample below but this just returns a 401 unauthorised error.

// bodyData and apiKey are defined above in my code
const base64EncodedApiKey = Buffer.from(apiKey).toString('base64');
const response = await api.requestJira(route`/jsm/assets/workspace/${workspaceId}/v1/object/create`, {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${base64EncodedApiKey}`,
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(bodyData)
})

I have also tried making a request using plain Node Fetch request to the full URL of https://api.atlassian.com/jsm/assets/workspace/${workspaceId}/v1/object/create` and passing in the API key, but still get the same 401 unauthorised error provided by Atlassian.

Can someone please confirm whether calling the Asset APIs is supported from Forge as this doesn’t seem possible from the approaches I have tried?

If it is supported, can you please give an example of calling the Create Asset API from Forge and add examples from Forge to the Assets Rest API documentation please?

Regards,
Kristian

Hi @kwalker, have you tried making the request outside of your Forge app? Like using curl or a similar client?
If it does work, I will need some more information on the request, I would recommend raising a support ticket and someone on our side will investigate it.
If it doesn’t work outside the Forge app, then it might mean that the user invoking the app doesn’t have access to this particular instance of JSM.

Hi Kristian,

To use the Assets REST API from a Forge app, you need to specify the appropriate scopes in your manifest.yml. From what I understand, these APIs currently only work when called using asApp() — not asUser().

To enable this, add the following scopes to your manifest:

permissions:
  scopes:
    - write:cmdb-object:jira
    - read:cmdb-object:jira

Once these scopes are added and deployed, your call using api.asApp() should start working — assuming the app has been granted permission and installed correctly in the site.