Skip to content

Commit 284f64b

Browse files
committed
Update notion-api.ts
1 parent 77d0f92 commit 284f64b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/notion-client/src/notion-api.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,24 @@ export class NotionAPI {
148148
const collectionView =
149149
recordMap.collection_view[collectionViewId]?.value
150150

151+
// Get the space_id from the collection block
152+
const collectionBlock = Object.values(recordMap.block).find(
153+
(b) =>
154+
b?.value &&
155+
(b.value.type === 'collection_view' ||
156+
b.value.type === 'collection_view_page') &&
157+
getBlockCollectionId(b.value, recordMap) === collectionId
158+
)
159+
const spaceId = collectionBlock?.value?.space_id
160+
151161
try {
152162
const collectionData = await this.getCollectionData(
153163
collectionId,
154164
collectionViewId,
155165
collectionView,
156166
{
157167
limit: collectionReducerLimit,
168+
spaceId,
158169
ofetchOptions
159170
}
160171
)
@@ -437,6 +448,7 @@ export class NotionAPI {
437448
searchQuery = '',
438449
userTimeZone = this._userTimeZone,
439450
loadContentCover = true,
451+
spaceId,
440452
ofetchOptions
441453
}: {
442454
type?: notion.CollectionViewType
@@ -445,6 +457,7 @@ export class NotionAPI {
445457
userTimeZone?: string
446458
userLocale?: string
447459
loadContentCover?: boolean
460+
spaceId?: string
448461
ofetchOptions?: OfetchOptions
449462
} = {}
450463
) {
@@ -614,6 +627,11 @@ export class NotionAPI {
614627
// )
615628
// }
616629

630+
const headers: any = {}
631+
if (spaceId) {
632+
headers['x-notion-space-id'] = spaceId
633+
}
634+
617635
return this.fetch<notion.CollectionInstance>({
618636
endpoint: 'queryCollection',
619637
body: {
@@ -629,6 +647,7 @@ export class NotionAPI {
629647
},
630648
loader
631649
},
650+
headers,
632651
ofetchOptions: {
633652
timeout: 60_000,
634653
...ofetchOptions,

0 commit comments

Comments
 (0)