google-cloud-platformdialogflow-esgoogle-apis-explorer

How to import knowledge base through api?


https://cloud.google.com/dialogflow/es/docs/reference/rest/v2beta1/projects.knowledgeBases.documents/import

Consider I'm having an csv file to be imported in a cloud storage, How exactly do I execute this above API request and import the knowledge base qna's, I've added the documentation link above, I'm getting the below error too

enter image description here


Solution

  • Change the parent to projects/your-project-id/knowledgeBases/xxxxxx and import should accept it.

    But I suggest to use projects.knowledgeBases.documents.create if you are planning to create a knowledge base from scratch using a CSV file. See sample request via projects.knowledgeBases.documents.create:

    parent: projects/your-project-id/knowledgeBases/xxxxx
    importGcsCustomMetadata: false
    
    Request Body:
    {
      "contentUri": "gs://my-bucket/faq.csv",
      "displayName": "test_csv",
      "knowledgeTypes": [
        "FAQ"
      ],
      "mimeType": "text/csv"
    }
    

    Returns HTTP 200:

    {
      "name": "projects/your-project-id/locations/us/operations/document-create-20210829-21261630297603-6127fbb9-0000-21dc-bec9-240588717654"
    }
    

    Created knowledge base in Dialogflow console:

    enter image description here