MCPcopy Index your code
hub / github.com/simstudioai/sim / listDocumentsV2

Function listDocumentsV2

apps/sim/connectors/confluence/confluence.ts:353–423  ·  view source on GitHub ↗

* Lists documents using the v2 API for a single content type (pages or blogposts).

(
  cloudId: string,
  accessToken: string,
  domain: string,
  spaceId: string,
  spaceKey: string,
  contentType: string,
  maxPages: number,
  cursor?: string,
  syncContext?: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

351 * Lists documents using the v2 API for a single content type (pages or blogposts).
352 */
353async function listDocumentsV2(
354 cloudId: string,
355 accessToken: string,
356 domain: string,
357 spaceId: string,
358 spaceKey: string,
359 contentType: string,
360 maxPages: number,
361 cursor?: string,
362 syncContext?: Record<string, unknown>
363): Promise<ExternalDocumentList> {
364 const queryParams = new URLSearchParams()
365 queryParams.append('limit', '250')
366 if (cursor) {
367 queryParams.append('cursor', cursor)
368 }
369
370 const endpoint = contentType === 'blogpost' ? 'blogposts' : 'pages'
371 const url = `https://api.atlassian.com/ex/confluence/${cloudId}/wiki/api/v2/spaces/${spaceId}/${endpoint}?${queryParams.toString()}`
372
373 logger.info(`Listing ${endpoint} in space ${spaceKey} (ID: ${spaceId})`)
374
375 const response = await fetchWithRetry(url, {
376 method: 'GET',
377 headers: {
378 Accept: 'application/json',
379 Authorization: `Bearer ${accessToken}`,
380 },
381 })
382
383 if (!response.ok) {
384 const errorText = await response.text()
385 logger.error(`Failed to list Confluence ${endpoint}`, {
386 status: response.status,
387 error: errorText,
388 })
389 throw new Error(`Failed to list Confluence ${endpoint}: ${response.status}`)
390 }
391
392 const data = await response.json()
393 const results = data.results || []
394
395 const documents: ExternalDocument[] = results.map((page: Record<string, unknown>) => {
396 const links = page._links as Record<string, string> | undefined
397 return pageToStub(page, {
398 spaceId: page.spaceId,
399 sourceUrl: links?.webui ? `https://${domain}/wiki${links.webui}` : undefined,
400 })
401 })
402
403 let nextCursor: string | undefined
404 const nextLink = (data._links as Record<string, string>)?.next
405 if (nextLink) {
406 try {
407 nextCursor = new URL(nextLink, 'https://placeholder').searchParams.get('cursor') || undefined
408 } catch {
409 // Ignore malformed URLs
410 }

Callers 2

confluence.tsFile · 0.85
listAllContentTypesFunction · 0.85

Calls 7

fetchWithRetryFunction · 0.90
infoMethod · 0.80
textMethod · 0.80
errorMethod · 0.80
pageToStubFunction · 0.70
getMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected