(cloudId: string, accessToken: string)
| 114 | * @throws If discovery fails or no workspace is provisioned |
| 115 | */ |
| 116 | export async function getAssetsWorkspaceId(cloudId: string, accessToken: string): Promise<string> { |
| 117 | const response = await fetch( |
| 118 | `https://api.atlassian.com/ex/jira/${cloudId}/rest/servicedeskapi/assets/workspace`, |
| 119 | { method: 'GET', headers: getJsmHeaders(accessToken) } |
| 120 | ) |
| 121 | |
| 122 | if (!response.ok) { |
| 123 | const errorText = await response.text() |
| 124 | throw new Error( |
| 125 | `Failed to resolve Assets workspace: ${response.status} - ${errorText || response.statusText}` |
| 126 | ) |
| 127 | } |
| 128 | |
| 129 | const data = await response.json() |
| 130 | const workspaceId: string | undefined = data?.values?.[0]?.workspaceId |
| 131 | |
| 132 | if (!workspaceId) { |
| 133 | throw new Error( |
| 134 | 'No Assets workspace found for this site. Assets (Insight) may not be enabled on the Jira instance.' |
| 135 | ) |
| 136 | } |
| 137 | |
| 138 | return workspaceId |
| 139 | } |
no test coverage detected