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

Function fetchAllItems

apps/sim/app/api/tools/webflow/items/route.ts:43–83  ·  view source on GitHub ↗

* Lists all items in a Webflow collection using `offset`/`limit` pagination * (limit capped at 100), advancing the numeric `offset` until the accumulated * count reaches `pagination.total` so the full set is returned. Bounded by * `WEBFLOW_MAX_ITEMS_PAGES`; logs a warning rather than silently dro

(accessToken: string, collectionId: string)

Source from the content-addressed store, hash-verified

41 * when the cap is hit.
42 */
43async function fetchAllItems(accessToken: string, collectionId: string): Promise<WebflowItem[]> {
44 const items: WebflowItem[] = []
45 let offset = 0
46
47 for (let page = 0; page < WEBFLOW_MAX_ITEMS_PAGES; page++) {
48 const url = new URL(`https://api.webflow.com/v2/collections/${collectionId}/items`)
49 url.searchParams.set('limit', String(WEBFLOW_PAGE_LIMIT))
50 url.searchParams.set('offset', String(offset))
51
52 const response = await fetch(url.toString(), {
53 headers: {
54 Authorization: `Bearer ${accessToken}`,
55 accept: 'application/json',
56 },
57 })
58
59 if (!response.ok) {
60 const errorData = await response.json().catch(() => ({}))
61 throw new WebflowFetchError(response.status, errorData)
62 }
63
64 const data = (await response.json()) as WebflowItemsPage
65 const pageItems = data.items || []
66 items.push(...pageItems)
67
68 const total = data.pagination?.total
69 offset += pageItems.length
70 if (pageItems.length === 0 || (typeof total === 'number' && items.length >= total)) {
71 return items
72 }
73
74 if (page === WEBFLOW_MAX_ITEMS_PAGES - 1) {
75 logger.warn('Webflow items listing hit pagination cap; item list may be incomplete', {
76 collectionId,
77 pages: WEBFLOW_MAX_ITEMS_PAGES,
78 })
79 }
80 }
81
82 return items
83}
84
85class WebflowFetchError extends Error {
86 constructor(

Callers 1

route.tsFile · 0.85

Calls 4

setMethod · 0.65
warnMethod · 0.65
toStringMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected