googleapis / googleapis/google-cloud-node

[@google-cloud/retail] Unable to make requests to desired project via SearchServiceClient

Open
#4,339 3 comments 3 reactions 1 assignee Claimed by @sofisl View on GitHub
priority: p2 type: bug
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

#### Environment details

- which product (packages/*): `@google-cloud/retail`

#### Steps to reproduce

Hello,

I am trying to setup an app that consumes the google-cloud retail API using the Node.js SDK. The SDK is authorized using a SA private key, via `GOOGLE_APPLICATION_CREDENTIALS` env. The SA has access to multiple projects, one of which has the Retail API enabled.

However, no matter how explicitly I specify which project I want the requests sent to, they are being sent to an another project anyway. My sample code looks something like this:

```ts
const searchServiceClient = new SearchServiceClient({
projectId: 'desired-project-id',
});

const [results, request, response] = await searchServiceClient.search(
{
placement: 'placement',
query: 'query',
visitorId: 'some-user-id',
offset: 0,
pageSize: 1,
userInfo: {
userId: 'some-user-id',
},
},
{ autoPaginate: false, maxResults: 1 }
);
```

Even though I specify the `projectId` twice - once in the `SearchServiceClient` constructor and another time within `placement`, the requests end up being sent to a project different than `desired-project-id`.

I have tried multiple solutions, from hacking the `project_id` field in SA credentials, to ensuring the `GOOGLE_CLOUD_PROJECT` env is not set by accident. Nothing seemed to work with the Retail SDK.

I encountered similar problems with a different SDK previously, however then specifying the `projectId` in the constructor seemed to solve the issue. With the Retail SDK, I was only able to make it work with my own Application Default Credentials, but that's not a feasible option for remote environments.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.