diff --git a/packages/notion-client/src/notion-api.ts b/packages/notion-client/src/notion-api.ts index 9866a892..ca21f732 100644 --- a/packages/notion-client/src/notion-api.ts +++ b/packages/notion-client/src/notion-api.ts @@ -148,6 +148,16 @@ export class NotionAPI { const collectionView = recordMap.collection_view[collectionViewId]?.value + // Get the space_id from the collection block + const collectionBlock = Object.values(recordMap.block).find( + (b) => + b?.value && + (b.value.type === 'collection_view' || + b.value.type === 'collection_view_page') && + getBlockCollectionId(b.value, recordMap) === collectionId + ) + const spaceId = collectionBlock?.value?.space_id + try { const collectionData = await this.getCollectionData( collectionId, @@ -155,6 +165,7 @@ export class NotionAPI { collectionView, { limit: collectionReducerLimit, + spaceId, ofetchOptions } ) @@ -437,6 +448,7 @@ export class NotionAPI { searchQuery = '', userTimeZone = this._userTimeZone, loadContentCover = true, + spaceId, ofetchOptions }: { type?: notion.CollectionViewType @@ -445,6 +457,7 @@ export class NotionAPI { userTimeZone?: string userLocale?: string loadContentCover?: boolean + spaceId?: string ofetchOptions?: OfetchOptions } = {} ) { @@ -614,6 +627,11 @@ export class NotionAPI { // ) // } + const headers: any = {} + if (spaceId) { + headers['x-notion-space-id'] = spaceId + } + return this.fetch({ endpoint: 'queryCollection', body: { @@ -629,6 +647,7 @@ export class NotionAPI { }, loader }, + headers, ofetchOptions: { timeout: 60_000, ...ofetchOptions,