Skip to content

Commit 4498110

Browse files
Merge pull request #670 from wustep/maybe_fix_qc
2 parents 1411992 + 284f64b commit 4498110

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
@@ -152,13 +152,24 @@ export class NotionAPI {
152152
const collectionView =
153153
recordMap.collection_view[collectionViewId]?.value
154154

155+
// Get the space_id from the collection block
156+
const collectionBlock = Object.values(recordMap.block).find(
157+
(b) =>
158+
b?.value &&
159+
(b.value.type === 'collection_view' ||
160+
b.value.type === 'collection_view_page') &&
161+
getBlockCollectionId(b.value, recordMap) === collectionId
162+
)
163+
const spaceId = collectionBlock?.value?.space_id
164+
155165
try {
156166
const collectionData = await this.getCollectionData(
157167
collectionId,
158168
collectionViewId,
159169
collectionView,
160170
{
161171
limit: collectionReducerLimit,
172+
spaceId,
162173
ofetchOptions
163174
}
164175
)
@@ -441,6 +452,7 @@ export class NotionAPI {
441452
searchQuery = '',
442453
userTimeZone = this._userTimeZone,
443454
loadContentCover = true,
455+
spaceId,
444456
ofetchOptions
445457
}: {
446458
type?: notion.CollectionViewType
@@ -449,6 +461,7 @@ export class NotionAPI {
449461
userTimeZone?: string
450462
userLocale?: string
451463
loadContentCover?: boolean
464+
spaceId?: string
452465
ofetchOptions?: OfetchOptions
453466
} = {}
454467
) {
@@ -618,6 +631,11 @@ export class NotionAPI {
618631
// )
619632
// }
620633

634+
const headers: any = {}
635+
if (spaceId) {
636+
headers['x-notion-space-id'] = spaceId
637+
}
638+
621639
return this.fetch<notion.CollectionInstance>({
622640
endpoint: 'queryCollection',
623641
body: {
@@ -633,6 +651,7 @@ export class NotionAPI {
633651
},
634652
loader
635653
},
654+
headers,
636655
ofetchOptions: {
637656
timeout: 60_000,
638657
...ofetchOptions,

0 commit comments

Comments
 (0)