Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a spreadsheet document with the JWT causes an error #701

Closed
Ivokato opened this issue Aug 23, 2024 · 3 comments · May be fixed by Pablo11111544545/moneyman#1, WontonSam/website#46 or WontonSam/website#59

Comments

@Ivokato
Copy link

Ivokato commented Aug 23, 2024

After reinstalling my node modules I got this error:
Cannot use api key only to create a new spreadsheet - it is only usable for read-only access of public docs

My bare minimum code taken from the official documentation is failing:

import {JWT} from 'google-auth-library'
import {GoogleSpreadsheet} from 'google-spreadsheet';

// I put key redacted here in the issue but used real private key in my code
const key = '-----BEGIN PRIVATE KEY-----(key redacted)-----END PRIVATE KEY-----\n';

const SCOPES = [
  'https://www.googleapis.com/auth/spreadsheets',
  'https://www.googleapis.com/auth/drive.file',
];

const jwt = new JWT({
  email: 'agent@company.iam.gserviceaccount.com',
  key,
  scopes: SCOPES,
});

GoogleSpreadsheet.createNewSpreadsheetDocument(jwt, {title: 'hello'}))
.then(result => {
  console.log('has result!: ', !!result);
}).catch(error => {
  console.log(error.message);
});

I figured out that the error is thrown because there is a key called "apiKey" in the JWT. Downgrading the google-auth-library to 9.13.0 has solved the issue for me so I would recommend either fixing the dependency or updating the check that throws the error

@niclake
Copy link

niclake commented Aug 27, 2024

I don't have much to offer, but curiously, have you tried key: key, inside defining your JWT?

@Sma1lboy
Copy link

I met same issue with official documentation code Cannot use api key only to create a new spreadsheet - it is only usable for read-only access of public docs Seems No permission from service account to create spreadsheet

@theoephraim
Copy link
Owner

fix incoming shortly!

junedomingo added a commit to junedomingo/node-google-spreadsheet that referenced this issue Sep 23, 2024
* main:
  wiring up github action to dmno
  chore: release v4.1.4
  add dmno and remove/encrypt test-related secrets, swap jest for vitest
  fix(updateProperties): getFieldMask ignore gridProperties (theoephraim#674)
  chore: release v4.1.3
  fix bugs introduced by PRs
  update axios, fix new google-auth-library issue, fixes theoephraim#701 theoephraim#700
  Read headers in batch on getRows() (theoephraim#693)
  Update authentication.md
  allow CI manual reruns
  Update FUNDING.yml
  use correct type in docs

# Conflicts:
#	.gitignore
#	pnpm-lock.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment