So, I am trying to fetch data from my Google Sheets using REST API v4. The URL for the spreadsheet is
https://docs.google.com/spreadsheets/d/1OaknELJVzHxsz5UkH4asuC_xIjgVF3s7JldrxiVuRc/edit#gid=2107620388
So, my spreadsheetId is 1OaknELJVzHxsz5UkH4asuC_xIjgVF3s7JldrxiVuRc.
I am following this link to fetch the data. The API to use, as per the document is
GET https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5
Now, for the sheet, I have 2 sheets - transactions and categories.

So, my final URL to use became
https://sheets.googleapis.com/v4/spreadsheets/1OaknELJVzHxsz5UkH4asuEC_xIjgVF3s7JldrxiVuRc/values/transactions
I used the following curl call to fetch the data
curl -v \
-H 'Authorization: Bearer ya29.GlxSB5uTisAfJ3umjYbGGdHBWeeuoBpQtytjdHc2QfP2lwVWqsQ7RwT-Or0z7VRAVQzilVWkweZ2WcH3TQqVnmoCZDe3rTn3euZ4MsoV1mCUpNh2bV-KHEhD16Q' \
-H 'Content-Type: application/json' \
https://sheets.googleapis.com/v4/spreadsheets/1OaknELJVzHxsz5UkH4asuEC_xIjgVF3s7JldrxiVuRc/values/transactions
But, I get the error as below
* Trying 2607:f8b0:400a:804::200a...
* TCP_NODELAY set
* Connected to sheets.googleapis.com (2607:f8b0:400a:804::200a) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google LLC; CN=*.googleapis.com
* start date: Jul 2 19:21:00 2019 GMT
* expire date: Sep 24 18:57:00 2019 GMT
* subjectAltName: host "sheets.googleapis.com" matched cert's "*.googleapis.com"
* issuer: C=US; O=Google Trust Services; CN=Google Internet Authority G3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fe5d7800000)
> GET /v4/spreadsheets/1OaknELJVzHxsUkH4asuEC_xIjgVF3s7JldrxiVuRc/values/transactions HTTP/2
> Host: sheets.googleapis.com
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: Bearer ya29.GlxSB5uTisAfJ3umjYbGGdHBWeeutytjdHc2QfP2lwVWqsQ7RwT-Or0z7VRAVQzilVWkweZ2WcH3TQqVnmoCZAehDe3rTn3euZ4MsoV1mCUpNh2bV-KHEhD16Q
> Content-Type: application/json
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 404
< vary: X-Origin
< vary: Referer
< vary: Origin,Accept-Encoding
< content-type: application/json; charset=UTF-8
< date: Fri, 26 Jul 2019 23:34:05 GMT
< server: ESF
< cache-control: private
< x-xss-protection: 0
< x-frame-options: SAMEORIGIN
< alt-svc: quic=":443"; ma=2592000; v="46,43,39"
< accept-ranges: none
<
{
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND"
}
}
* Connection #0 to host sheets.googleapis.com left intact
I tried other A1 Notation, but none of them worked
transactions!A:B
transactions!A1:B2
categories!A:B
transactions
categories
I know that my Bearer token is valid and in scope because I am able to create a spreadsheet.
Also, I am using the following scope for my app
https://www.googleapis.com/auth/drive.file
What am I doing wrong here? Thanks
If my understanding is correct, how about this answer?
When the error message of Requested entity was not found. occurs, the following reasons can be considered.
Unable to parse range: ### is shown.https://www.googleapis.com/auth/drive.file, the files by created with the access token including this scope can be accessed. You might try to access to the Spreadsheet which is not created with the the access token including the scope.From your question, when the Spreadsheet ID is correct, it is considered that the latter is the reason of your issue.
In order to avoid this, I would like to propose the following 2 patterns. Please think of this answer as just one of several answers.
When you are required to use the scope of https://www.googleapis.com/auth/drive.file, how about this?
By the method of spreadsheets.create, create new Spreadsheet using the access token including the scope of https://www.googleapis.com/auth/drive.file. ANd set some values to the created Spreadsheet. This can be done by manual operation. And please retrieve the Spreadsheet ID.
curl \
-H 'Authorization: Bearer ###' \
-H 'Content-Type: application/json' \
-d '{"properties": {"title": "sample"}}' \
https://sheets.googleapis.com/v4/spreadsheets
Retrieve the values from the created Spreadsheet using the method of spreadsheets.values.get of Sheets API.
curl \
-H 'Authorization: Bearer ###' \
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/transactions
https://www.googleapis.com/auth/drive.file as follows.View and manage Google Drive files and folders that you have opened or created with this app
When you can use other scope instead of https://www.googleapis.com/auth/drive.file, how about using the scope of https://www.googleapis.com/auth/spreadsheets.readonly? In this case, you can retrieve the values from the existing Spreadsheet that you have the error of Requested entity was not found..
curl \
-H 'Authorization: Bearer ###' \
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/transactions
https://www.googleapis.com/auth/spreadsheets. as the scope. Please be careful this.If I misunderstood your question and this was not the direction you want, I apologize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With