Error passing location to dialogflow.projects.agent.search

I want to fetch a user’s Dialogflow agents from a specific data region using Nodejs googleapis package. When I pass europe-west2 to dialogflow.projects.agent.search, I get the following error:

400 – “Dialogflow server in ‘us’ received request for resources located in ‘europe-west2.'”

Do I need to specify the location when I spin up the dialogflow constant with the auth and api version? The only mention of location I found in v2beta1.d.ts is for geoLocation, which wouldn’t apply here. There isn’t any mention of an apiEndpoint either like in this question asked here.

Here’s my code:

const dialogflow = await google.dialogflow({
  auth: oAuth2Client
  version: 'v2beta1'
  // declare location here as well?
})

try {
  const fetchAgentsResponse = await dialogflow.projects.agent.search({
    parent: `projects/-/locations/${location}`
  })
} catch (e) {
  throw e
  // receive the 400 error mentioned above
}

Answer

I edited the Service Path for SessionsClient to take in the bot’s location ahead of the detectIntent call.

SessionsClient.servicePath = `${location}-dialogflow.googleapis.com`