Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken search function #505

Merged
merged 1 commit into from
Aug 8, 2023
Merged

Conversation

Armster15
Copy link
Contributor

Description

Problem: The search function is currently broken: we get a mysterious 405 error when we prop open the dev console and inspect the search request:
An image showing https://transitivebullsh.it with a failed POST request to the search api route, with a status code of 405

It turns out that Notion slightly changed the API for search, resulting in the way the library notion-client sends the API request to Notion for searching to be broken and throw an error:
An image of Postman showing the result of the API request sent to Notion to search by notion-client
The request body in the above screenshot was generated by notion-client and I just put it in Postman to show the error that is thrown by the Notion API.

Luckily this was a quick fix! I went to Notion and performed a search and inspected how they sent the API request, and noticed a slight difference:
An image showing an API request to the Notion search API route by the Notion web app, which reveals a difference in the way the sort key is sent
For the sort key, notion-client currently sends the following:

"sort": "Relevance"

While the Notion web app sends:

"sort": {
    "field": "relevance"
}

So I changed notion-client to send the sort the same way the Notion web app sends it (which you can see in the code of this pull request) and the search function started working again!
The search function working again!

Notion Test Page ID

cebbcc4b7b784d63819ef7db02054b49

@vercel
Copy link

vercel bot commented Jul 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-notion-x ✅ Ready (Inspect) Visit Preview Jul 7, 2023 8:47pm
react-notion-x-minimal-demo ✅ Ready (Inspect) Visit Preview Jul 7, 2023 8:47pm

@hilmanski
Copy link

thanks @Armster15 appreciate it

@dnx04
Copy link

dnx04 commented Jul 20, 2023

@transitive-bullshit please approve this pull request

ryngonzalez added a commit to ryngonzalez/react-notion-x that referenced this pull request Jul 25, 2023
@transitive-bullshit transitive-bullshit merged commit 3aba73c into NotionX:master Aug 8, 2023
@transitive-bullshit
Copy link
Member

Thanks!

@Jessie-jzn
Copy link

the bug has fixed, but version: "6.16.1" donesn't publish at npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants