10

I am trying to access a Google DialogFlow from a Windows Java application. I have the environment variable, GOOGLE_APPLICATION_CREDENTIALS, properly set and I can call other Google APIs. However, when I call:

DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput);

I receive a grpc exception:

PERMISSION_DENIED: IAM permission 'dialogflow.sessions.detectIntent' on 'projects/newagent-a0ef5/agent' denied.Session Path: projects/NewAgent/agent/sessions/xxxx

"newagent-a0ef5" is the project ID of my flow. "xxxx" is just a random Session ID token.

I understand that I have to enable dialogflow.sessions.detectIntent access, but I cannot figure out where. I created a custom role with that value and added it to the three IAM accounts associated with my flow. I have also enabled the DialogFlow API.

Does anyone know where I add this missing permission?

Community
  • 1
  • 1
Andrew Prokop
  • 121
  • 1
  • 1
  • 4
  • Check whether you are associated with the correct GCP with the dialogflow project. Also check whether your IAM roles are associated for Dialogflow client. – Ashwin Chandar Apr 29 '18 at 18:21
  • 1
    Have you already gone through the API credentials steps on the Google Cloud Platform? From the dropdown go to APIs & Services > Credentials > Create Credentials > Service Account key > New service acct, role: project > owner, JSON. [Here](https://pantheon.corp.google.com/apis/credentials/serviceaccountkey?_ga=2.133098830.-1362814056.1530554298&project=sample-testing-213317&folder&organizationId=433637338589) – Sarah Dwyer Aug 14 '18 at 17:44

5 Answers5

7

I did all the IAM steps properly, but I was passing the wrong Project ID to detectIntent. So I guess a couple things to check...

  • Make sure the Project ID is correct. Your session path should be 'projects/<Project ID>/agent/sessions/<Session ID>'.
  • Make sure you are using a service account with the Dialogflow API Client role.
  • Try getting it to work in API Explorer
Keeth
  • 2,100
  • 2
  • 21
  • 29
  • Had to add the role of "Dialogflow API Admin" to get mine working, FYI. – Midnightly Coder Oct 29 '18 at 21:48
  • Dialogflow documentation seems to say to use Project Name instead of Project ID, is it incorrect? Also, how can I know what I should put for Session ID? Thanks! – Tilek Nov 14 '18 at 08:17
  • @Tilek `Session ID` is a number or ID that you declare. For example, when you get a twilio message, you can pass `MessageID` from the Request body as a `sessionId` to your `sessionPath`. – Gus Oct 24 '19 at 00:21
1

I had the same problem when I was creating a chatbot. I solve this by using a Dialogflow API Client role. I also had to change my ruby version from 2.6 to 2.5.1.

It is important to remember that the GOOGLE_APPLICATION_CREDENTIALS have to point to the key .json file. To avoid problems set the path to the json file in the .bashrc file. So you don't have execute export GOOGLE_APPLICATION_CREDENTIALS="[PATH]" every time you restart your machine.

Robson Sampaio
  • 307
  • 1
  • 5
1

There are following things we need to check:

  1. You are right project ID:
  2. IAM role should be ADMIN : Admin Project > Owner(Full access to all Dialogflow (console and API) and GCP resources. Can use console to create agent.)

Ref to add IAM user(don't forget to choose rule as Admin): https://dialogflow.com/docs/reference/v2-auth-setup

Quasipickle
  • 4,383
  • 1
  • 31
  • 53
alok
  • 2,718
  • 21
  • 17
  • I have all my service accounts as Project -> Owner and it works fine –  Dec 08 '19 at 07:28
0

In my case the error occurred because GOOGLE_CLOUD_PROJECT was set with Project Name (a word in mixed case), but it should be ProjectID (a word lower case). After I changed it to ProjectID, it started working. HTH

Terry
  • 310
  • 3
  • 9
0

i also had this error, it could be that you're failing to set environment on the json credentials, make sure it is correct, i didn't need an admin role for mine.

to set path for GOOGLE_APPLICATION_CREDENTIALS on cmd on wherever directory you are, point your json file as if you would do on environment varialbes(will be removed when you close cmd):

set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\Owner\Desktop\reactbot\config\ddssa-adietv-aasddss.json

gpbaculio
  • 5,693
  • 13
  • 60
  • 102