Search code examples
pythonapidialogflow-esrolespermission-denied

Issue Creating a Knowledge Base inside a Dialogflow agent using Dialogflow Python API


Unable to create knowledge base in dialog flow using python dialogflow client.

Given admin permission for dialogflow in IAM service accounts.

I have given the Dialogflow Admin Role to the client mail I'm using.

I used a json key generated for a service account and exported it as an environmental variable

this is the code I used:

import dialogflow_v2beta1 as dialogflow

    client = dialogflow.KnowledgeBasesClient()
    project_path = client.project_path(project_id)

    knowledge_base = dialogflow.types.KnowledgeBase(
    display_name=display_name)
    response = client.create_knowledge_base(project_path, knowledge_base)

I'm able to create/delete/list a document inside already created Knowledge base but creating a knowledge base throws this error

error: google.api_core.exceptions.PermissionDenied: 403 IAM permission 'dialogflow.knowledgeBases.create' on 'projects/api_test2' denied


Solution

  • The issue seems to be with the service account I'm using to deal with knowledge bases and apparently there isn't a way to provide the permission to deal with knowledge bases for dialogflow python client as of now(Kindly correct me,if I'm wrong).

    The only work around I found was to use curl operations to deal with knowledge bases.

    After using curl to operate on knowledge bases I decided to change all my python client code to curl and subprocesses. Its pretty simple when compared to the python client.

    Edit (07/27/2020) : nothings changed with the IAM permissions for Dialogflow python client, may be I got to wait till KnowledgeBases comes out of beta stage. Meanwhile, realized requests are better way of doing this than curl and subprocess and would recommend doing the same