google-cloud-platformdialogflow-esgoogle-cloud-logging

Extract conversation history in DialogFlow request


I'm having trouble retrieving the requests and responses from a chatbot I've created in Dialogflow using the Cloud Logging REST API. The thing is, I can see the name of the log, which is dialogflow_agent, but I don't see anything else when I try to make this request:

`GET https://logging.googleapis.com/v2/projects/voteugr/logs/
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json`

Upon performing this request, I'm not receiving an error, but instead, I'm getting this:

`{
  "logNames": [
    "projects/voteugr/logs/cloudaudit.googleapis.com%2Factivity",
    "projects/voteugr/logs/dialogflow_agent"
  ]
}`

But if I try to access the specific case of dialogflow_agent, it returns a 404 error. How do I get a JSON with the logs, which are being stored in Cloud Logging? (I can download them manually, but I'd like to do it through a REST API to automate everything)


Solution

  • That is not the correct endpoint to retrieve log entries.

    The GET https://logging.googleapis.com/v2/projects/YOUR_PROJECT_ID/logs/ is used to retrieve the list of names of logs, not the individual log entries themselves.

    To retrieve the log entries, you should use the entries:list method

    Which is POST https://logging.googleapis.com/v2/entries:list.

    curl "https://logging.googleapis.com/v2/entries:list" \
      -X POST -H "Authorization: Bearer ACCESS_TOKEN" -H "Content-Type: application/json" \
      -d'
      {
        "projectIds": [
          "voteugr"
        ],
        "filter":"logName=\"projects/voteugr/logs/dialogflow_agent\"",
        "pageSize": 100,
        "orderBy": "timestamp desc"
      }'
    

    This will return a list of log entries in a JSON format.

    "filter" part in the request body is used to query specific logs

    To learn more about it see the next documentation:

    https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list