When the Notion API asks for a database ID, open the database as a full page and copy the long hash from the URL, everything before ?v=. Ignore the part after ?v=, that identifies the view. Then click the three dots on the database, go to Connections, and add your integration. Without that sharing step the API cant see the database even with a valid token.

Context: Stack Overflow #67728038 (accepted answer, 36 votes): the asker could not find the database ID anywhere for the Notion API. The accepted answer: open the database as a full page and take the long hash in the URL before the ?v= query part, that is the database ID, while the hash after ?v= is just the view ID. It also notes you must add your integration to the database via the Add connections button, or API calls against it will fail.