I’ve got a forge app that’s a dashboard gadget which queries the JSM Assets system and simply counts records and comes up with totals for them. It all works great, but I can’t seem to figure out how to programmatically set the Workspace id in the code. I’ve seen plenty of sample code that simply uses $workspaceId but has no explanation how that variable is set. I’ve attempted to grab it from a simple requestJira call, but I get a 401 error. I’ve added read:servicedesk-request to my manifest as that’s what the docs say is necessary to retrieve the workspace id. I’ve also retrieved the context using useProductContext and the workspace id is in there, but it shows as ‘undefined’.
@ErikEkengren which API method are you calling that gives you the 401?
Check out these docs: https://developer.atlassian.com/cloud/assets/assets-rest-api-guide/workflow/#step-2:-discover-your-workspaceid
1 Like
const response = await api.asApp().requestJira(route(`/rest/servicedeskapi/assets/workspace`));
@nmansilla I’m trying to figure out how to take an Atlassian Forge app and distribute it to customers when we hit their JSM Assets system. It seems like the workspaceid is necessary and I could set it up so that they enter it in the configuration, but it seems like it should be easy enough to grab so the customer doesn’t need to enter that.
Did you find a way to get it in the end?
Never mind, in the end with the scope read:servicedesk-request
this is working:
const response = await api.asApp().requestJira(route`/rest/servicedeskapi/assets/workspace`);
const data = await response.json();
And returns:
{
size: 1,
start: 0,
limit: 50,
isLastPage: true,
_links: {
self: 'https://api.atlassian.com/rest/servicedeskapi/assets/workspace',
base: 'https://mydomain.atlassian.net',
context: ''
},
values: [ { workspaceId: 'my workspace id' } ]
}
I was making a POST request instead of a GET, stupid me.