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