Closed tattali closed 4 years ago
Can you describe in what way current code fails? A test case and a test page?
Hi, After further reading it seems thats older than the group filters feature : https://github.com/jamalex/notion-py/issues/94
the code do not fail but not filter
be sure to use the current filter structure
client := ¬ionapi.Client{}
client.AuthToken = "token"
collectionID := "collectionID"
collectionViewID := "collectionViewID
// I am not 100% sure about this query filter
// query Pages with "ok" as title
currentQuery := ¬ionapi.Query{
Filter: []*notionapi.QueryFilter{
{
Property: "title",
Comparator: "string_contains",
Value: "ok",
},
},
FilterOperator: "and",
}
resp, err := client.QueryCollection(collectionID, collectionViewID, currentQuery, ¬ionapi.User{})
if err != nil {
log.Fatalf("QueryCollection() failed with %s\n", err)
}
count := 0
for _, record := range resp.RecordMap.Blocks {
block := record.Block
// count only Pages
if len(block.GetProperty("title")) > 0 && block.IsPage() && !block.IsSubPage() && !block.IsLinkToPage() {
count++
}
}
log.Print(count) // output 108 for me, like if there is no filters
using the new structure to in the query_collection.go
so add Query2FilterGroup
and Query2Filter
and update Query
as it is described in the previous post
client := ¬ionapi.Client{}
client.AuthToken = "token"
collectionID := "collectionID"
collectionViewID := "collectionViewID
// query Pages with "ok" as title
newQuery := ¬ionapi.Query{
Filter: ¬ionapi.Query2FilterGroup{
Filters: []*notionapi.Query2FilterGroup{
{
Filter: ¬ionapi.Query2Filter{
Operator: "string_contains",
Value: struct {
Type string `json:"type"`
Value string `json:"value"`
}{
Type: "exact",
Value: "ok",
},
},
Property: "title",
},
},
Operator: "and",
},
}
resp, err := client.QueryCollection(collectionID, collectionViewID, newQuery, ¬ionapi.User{})
if err != nil {
log.Fatalf("QueryCollection() failed with %s\n", err)
}
count := 0
for _, record := range resp.RecordMap.Blocks {
block := record.Block
// count only Pages
if len(block.GetProperty("title")) > 0 && block.IsPage() && !block.IsSubPage() && !block.IsLinkToPage() {
count++
}
}
log.Print(count) // output 1 for me
Thanks
Hi, thanks for your outstanding work with this unofficial API !
But I find out that Notion team has improve the way to handle filters to add filter groups, since 28/05. Change log - Feature
This new way seems to break the actual filters structure so I update locally the
query_collection.go
to make it workAdd two new types
Update the
Query
typeI am not sure if this is a definitive way to handle QueryFilters because the
query
is now calledquery2
in CollectionViewsso update the collectionview too
This changes are working locally even if it is not fully typed.
I post it here because of the questions