( spreadsheetId: string, accessToken: string, driveId?: string )
| 240 | * unlike the Graph API URL which requires an access token. |
| 241 | */ |
| 242 | export async function getSpreadsheetWebUrl( |
| 243 | spreadsheetId: string, |
| 244 | accessToken: string, |
| 245 | driveId?: string |
| 246 | ): Promise<string> { |
| 247 | const basePath = getItemBasePath(spreadsheetId, driveId) |
| 248 | try { |
| 249 | const response = await fetch(`${basePath}?$select=id,webUrl`, { |
| 250 | headers: { |
| 251 | Authorization: `Bearer ${accessToken}`, |
| 252 | }, |
| 253 | }) |
| 254 | |
| 255 | if (!response.ok) { |
| 256 | logger.warn('Failed to fetch spreadsheet webUrl, using Graph API URL as fallback', { |
| 257 | spreadsheetId, |
| 258 | status: response.status, |
| 259 | }) |
| 260 | return basePath |
| 261 | } |
| 262 | |
| 263 | const data = await response.json() |
| 264 | return data.webUrl || basePath |
| 265 | } catch (error) { |
| 266 | logger.warn('Error fetching spreadsheet webUrl, using Graph API URL as fallback', { |
| 267 | spreadsheetId, |
| 268 | error, |
| 269 | }) |
| 270 | return basePath |
| 271 | } |
| 272 | } |
no test coverage detected