langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
51.76k stars 7.5k forks source link

Cannot link Notion #7383

Closed sweetkey closed 2 months ago

sweetkey commented 2 months ago

Self Checks

Dify version

0.7.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

click this "Add workspace" to create a dataset by importing data from Notion, but an error message shows up. image

✔️ Expected Behavior

https://docs.dify.ai/learn-more/use-cases/build-an-notion-ai-assistant

❌ Actual Behavior

{"error":"invalid_request","error_description":"query failed validation: query.client_id should be a string or undefined, instead was 0.","request_id":"2cae3411-0e34-49d2-9474-17c0218eec06"}

dosubot[bot] commented 2 months ago

Hello, @sweetkey! I'm here to help you with any bugs, questions, or contributions you might have. Let's work together to resolve the issue you're experiencing.

To resolve the "invalid_request" error related to query.client_id when trying to add a workspace from Notion in Dify version 0.7.0, ensure that the client_id is correctly set and passed in the authorization URL. The client_id is a crucial parameter for OAuth authentication and must be correctly configured.

Here is the relevant part of the code that constructs the authorization URL:

def get_authorization_url(self):
    params = {
        "client_id": self.client_id,
        "response_type": "code",
        "redirect_uri": self.redirect_uri,
        "owner": "user",
    }
    return f"{self._AUTH_URL}?{urllib.parse.urlencode(params)}"

Make sure that self.client_id is correctly initialized when creating an instance of NotionOAuth. If self.client_id is not set or is incorrect, it will result in an "invalid_request" error.

Example of initializing NotionOAuth:

notion_oauth = NotionOAuth(client_id="your_client_id", client_secret="your_client_secret", redirect_uri="your_redirect_uri")
authorization_url = notion_oauth.get_authorization_url()

Ensure that your_client_id, your_client_secret, and your_redirect_uri are correctly provided.

Additionally, if you are using the internal or public integration methods for Notion, make sure to configure the environment variables correctly in the .env file as follows:

For internal integration:

NOTION_INTEGRATION_TYPE=internal
NOTION_INTERNAL_SECRET=your_internal_secret

For public integration:

NOTION_INTEGRATION_TYPE=public
NOTION_CLIENT_SECRET=your_client_secret
NOTION_CLIENT_ID=your_client_id

These configurations are necessary to ensure that the integration with Notion works seamlessly and the client_id is correctly recognized.

For more detailed steps on setting up the integration, you can refer to the Dify documentation on importing data from Notion and configuring the integration:

  1. Authorization Verification: When creating a dataset and selecting the data source, click Sync from Notion Content -- Bind Now and follow the prompts to complete the authorization verification.
  2. Importing Notion Data: After completing the authorization verification, go to the create dataset page, click Sync from Notion Content, and select the authorized pages you need to import.
  3. Integration Configuration: Configure the relevant environment variables in the .env file based on whether you are using internal or public integration.

For internal integration:

For public integration:

Following these steps should help resolve the "invalid_request" error related to query.client_id [1][2][3][4].

To continue talking to Dosu, mention @dosu.

sweetkey commented 2 months ago

Thanks, I went to Notion Integration Page to enable Integration with an app, and copied & pasted the secret code back to Notion section in ".env", now it solves the error message issue.

niko2020 commented 3 weeks ago

sorry to bump that but a warning message instead of an error would be awesome