question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

While updating a row giving Google API error

See original GitHub issue

Hi @theoephraim ,

When Iam updating a row values in the google sheet, sometimes it gives below error:

Caught error while updating status in production report>>> { Error: Google API error - [401] Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
    at createError (E:\Pippin_Projects\titles-server\node_modules\axios\lib\core\createError.js:16:15)
    at settle (E:\Pippin_Projects\titles-server\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (E:\Pippin_Projects\titles-server\node_modules\axios\lib\adapters\http.js:236:11)
    at IncomingMessage.emit (events.js:194:15)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at endReadableNT (_stream_readable.js:1103:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  config:
   { url: '/',
     method: 'get',
     params: {},
     headers:
      { Accept: 'application/json, text/plain, */*',
        Authorization: 'Bearer undefined',
        'User-Agent': 'axios/0.19.2' },
     baseURL:
      'https://sheets.googleapis.com/v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI',
     transformRequest: [ [Function: transformRequest] ],
     transformResponse: [ [Function: transformResponse] ],
     timeout: 0,
     adapter: [Function: httpAdapter],
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     validateStatus: [Function: validateStatus],
     data: undefined },
  request:
   ClientRequest {
     domain: null,
     _events:
      [Object: null prototype] {
        socket: [Function],
        abort: [Function],
        aborted: [Function],
        error: [Function],
        timeout: [Function],
        prefinish: [Function: requestOnPrefinish] },
     _eventsCount: 6,
     _maxListeners: undefined,
     output: [],
     outputEncodings: [],
     outputCallbacks: [],
     outputSize: 0,
     writable: true,
     _last: true,
     chunkedEncoding: false,
     shouldKeepAlive: false,
     useChunkedEncodingByDefault: false,
     sendDate: false,
     _removedConnection: false,
     _removedContLen: false,
     _removedTE: false,
     _contentLength: 0,
     _hasBody: true,
     _trailer: '',
     finished: true,
     _headerSent: true,
     socket:
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: 'sheets.googleapis.com',
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 8,
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'sheets.googleapis.com',
        _readableState: [ReadableState],
        readable: false,
        domain: null,
        _maxListeners: undefined,
        _writableState: [WritableState],
        writable: false,
        allowHalfOpen: false,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: null,
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: [Circular],
        write: [Function: writeAfterFIN],
        [Symbol(res)]: [TLSWrap],
        [Symbol(asyncId)]: 18730,
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: null,
        [Symbol(kBytesRead)]: 864,
        [Symbol(kBytesWritten)]: 229,
        [Symbol(connect-options)]: [Object] },
     connection:
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: 'sheets.googleapis.com',
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 8,
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'sheets.googleapis.com',
        _readableState: [ReadableState],
        readable: false,
        domain: null,
        _maxListeners: undefined,
        _writableState: [WritableState],
        writable: false,
        allowHalfOpen: false,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: null,
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: [Circular],
        write: [Function: writeAfterFIN],
        [Symbol(res)]: [TLSWrap],
        [Symbol(asyncId)]: 18730,
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: null,
        [Symbol(kBytesRead)]: 864,
        [Symbol(kBytesWritten)]: 229,
        [Symbol(connect-options)]: [Object] },
     _header:
      'GET /v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI/ HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nAuthorization: Bearer undefined\r\nUser-Agent: axios/0.19.2\r\nHost: sheets.googleapis.com\r\nConnection: close\r\n\r\n',
     _onPendingData: [Function: noopPendingOutput],
     agent:
      Agent {
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object],
        requests: {},
        sockets: [Object],
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        maxCachedSessions: 100,
        _sessionCache: [Object] },
     socketPath: undefined,
     timeout: undefined,
     method: 'GET',
     path:
      '/v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI/',
     _ended: true,
     res:
      IncomingMessage {
        _readableState: [ReadableState],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        socket: [TLSSocket],
        connection: [TLSSocket],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Array],
        trailers: {},
        rawTrailers: [],
        aborted: false,
        upgrade: false,
        url: '',
        method: null,
        statusCode: 401,
        statusMessage: 'Unauthorized',
        client: [TLSSocket],
        _consuming: true,
        _dumped: false,
        req: [Circular],
        responseUrl:
         'https://sheets.googleapis.com/v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI/',
        redirects: [] },
     aborted: undefined,
     timeoutCb: null,
     upgradeOrConnect: false,
     parser: null,
     maxHeadersCount: null,
     _redirectable:
      Writable {
        _writableState: [WritableState],
        writable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        _options: [Object],
        _redirectCount: 0,
        _redirects: [],
        _requestBodyLength: 0,
        _requestBodyBuffers: [],
        _onNativeResponse: [Function],
        _currentRequest: [Circular],
        _currentUrl:
         'https://sheets.googleapis.com/v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI/' },
     [Symbol(isCorked)]: false,
     [Symbol(outHeadersKey)]:
      [Object: null prototype] {
        accept: [Array],
        authorization: [Array],
        'user-agent': [Array],
        host: [Array] } },
  response:
   { status: 401,
     statusText: 'Unauthorized',
     headers:
      { 'www-authenticate':
         'Bearer realm="https://accounts.google.com/", error="invalid_token"',
        vary: 'X-Origin, Referer, Origin,Accept-Encoding',
        'content-type': 'application/json; charset=UTF-8',
        date: 'Tue, 25 Feb 2020 09:42:18 GMT',
        server: 'ESF',
        'cache-control': 'private',
        'x-xss-protection': '0',
        'x-frame-options': 'SAMEORIGIN',
        'alt-svc':
         'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000',
        'accept-ranges': 'none',
        connection: 'close' },
     config:
      { url: '/',
        method: 'get',
        params: {},
        headers: [Object],
        baseURL:
         'https://sheets.googleapis.com/v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI',
        transformRequest: [Array],
        transformResponse: [Array],
        timeout: 0,
        adapter: [Function: httpAdapter],
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        validateStatus: [Function: validateStatus],
        data: undefined },
     request:
      ClientRequest {
        domain: null,
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: false,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: 0,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [TLSSocket],
        connection: [TLSSocket],
        _header:
         'GET /v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI/ HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nAuthorization: Bearer undefined\r\nUser-Agent: axios/0.19.2\r\nHost: sheets.googleapis.com\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Agent],
        socketPath: undefined,
        timeout: undefined,
        method: 'GET',
        path:
         '/v4/spreadsheets/1glk-vpeAsxeVn6wyhFcakXK-u1Ew03okfrey7bIlMsI/',
        _ended: true,
        res: [IncomingMessage],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        _redirectable: [Writable],
        [Symbol(isCorked)]: false,
        [Symbol(outHeadersKey)]: [Object] },
     data: { error: [Object] } },
  isAxiosError: true,
  toJSON: [Function] }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
theoephraimcommented, Feb 27, 2020

Are you calling useServiceAccountAuth multiple times? You should only call that once when the application starts up, rather than each time you are trying to update the sheet. It seems like that could be the issue if it is happening intermittently - one call is trying to reset the auth while another is in the middle of saving something.

1reaction
theoephraimcommented, Feb 25, 2020

@vinodhreddygs i think if you add a .catch you’ll likely see an error when you try to initialize the service account auth.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in updating rows Google Sheets API - Stack Overflow
Google caches the validation so once you approve the client via the browser pop up, it won't appear again. However, when you change...
Read more >
Error exception while adding a row in google spreadsheet
I am recently using Google spreadsheet API for creating spreadsheets and store data on them. I have followed the entire tut with specifying...
Read more >
Error messages | BigQuery - Google Cloud
This document describes error messages you might encounter when working with BigQuery, including HTTP error codes, job errors, and Google Cloud console ...
Read more >
Fix issues with your spreadsheet for bulk uploads
When you make changes with bulk uploads, you might encounter errors. Some of these errors might be due to how your spreadsheet is...
Read more >
API - Common Troubleshooting - Airtable Support
This error can also occur when creating or updating a record and writing a new value to a linked record field. If we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found