* Resolves a Confluence space key to its numeric space ID.
( cloudId: string, accessToken: string, spaceKey: string )
| 600 | * Resolves a Confluence space key to its numeric space ID. |
| 601 | */ |
| 602 | async function resolveSpaceId( |
| 603 | cloudId: string, |
| 604 | accessToken: string, |
| 605 | spaceKey: string |
| 606 | ): Promise<string> { |
| 607 | const url = `https://api.atlassian.com/ex/confluence/${cloudId}/wiki/api/v2/spaces?keys=${encodeURIComponent(spaceKey)}&limit=1` |
| 608 | |
| 609 | const response = await fetchWithRetry(url, { |
| 610 | method: 'GET', |
| 611 | headers: { |
| 612 | Accept: 'application/json', |
| 613 | Authorization: `Bearer ${accessToken}`, |
| 614 | }, |
| 615 | }) |
| 616 | |
| 617 | if (!response.ok) { |
| 618 | throw new Error(`Failed to resolve space key "${spaceKey}": ${response.status}`) |
| 619 | } |
| 620 | |
| 621 | const data = await response.json() |
| 622 | const results = data.results || [] |
| 623 | |
| 624 | if (results.length === 0) { |
| 625 | throw new Error(`Space "${spaceKey}" not found`) |
| 626 | } |
| 627 | |
| 628 | return String(results[0].id) |
| 629 | } |
no test coverage detected