googleapis / googleapis/google-cloud-node

Error "Precondition check failed"

Open
#7,747 1 comment 0 reactions 1 assignee Claimed by @sofisl View on GitHub
library: google-cloud-node-core priority: p3 type: question
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

I am using `googleapis` to send emails on behalf of my customers. It works fine for most customers but for one in particular, I get the following error :
```
Error: Precondition check failed.
at Gaxios._request (/home/nicolas/mi/node_modules/gaxios/build/src/gaxios.js:84:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async OAuth2Client.requestAsync (/home/nicolas/mi/node_modules/googleapis-common/node_modules/google-auth-library/build/src/auth/oauth2client.js:343:18)
at async Object.sendEmail (/home/nicolas/mi/src/utils/google_api.js:53:4)
at async Object.sendEmail (/home/nicolas/mi/src/utils/email_manager.js:264:3)
```
After a few searches on the web, I found out that this error is related to service accounts, but I am not using service accounts, I am authenticated with OAuth.
So what could it be ? Does it has to do with the type of Google account my customer owns ?

The code of my method for sending emails :
```
const { google } = require('googleapis');

async sendEmail(credentials, to, subject, message, options) {
const oauth = new google.auth.OAuth2(config.oauth_client_id, config.oauth_client_secret, `${webConfig.hostname}/mon-compte`);

// set the user credentials
oauth.setCredentials(credentials);

// build the email
const raw = buildEmail(to, subject, message, options);

// send the email
await google.gmail({ version: 'v1', auth: oauth }).users.messages.send({
userId: 'me',
resource: { raw }
});
}
```

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.