#
Authentication
You can add additional protection to your spreadsheet API by enabling token-based access to sheet's API. Once you turn it on, requests without an API token will result in errors.
In order to enable API protection, you'll need to go to the Sheets Dashboard and open the spreadsheet you want to protect. On this page, you will see the "Authentication" section, that looks like this:
Once you toggle "Enable Token Protection" switch, your API will start requiring token for access.
You can generate a new token by clicking the button at bottom of the section.
Be careful
Once you re-generate API token, the old one will stop working.
#
Accessing protected API
You have 2 options to access API with token:
#
Using query parameter
You can pass the token as a query parameter. Pass token as _x-api-token
query parameter.
For example, if your API endpoint is https://sheetrest.com/api/v1/SHEET_ID
, you can access it by adding ?_x-api-token={YOUR_AUTH_TOKEN}
to the URL.
curl -X GET \
"https://sheetrest.com/api/v1/SHEET_ID?_x-api-token=YOUR_AUTH_TOKEN"
fetch('https://sheetrest.com/api/v1/SHEET_ID?_x-api-token=YOUR_AUTH_TOKEN', {
method: 'GET',
headers: {
accept: 'application/json',
},
});
#
Using HTTP header
You can also pass the token as an HTTP header. You can pass token as X-API-Token
header.
curl \
-H 'X-API-Token: YOUR_AUTH_TOKEN' \
-X GET "https://sheetrest.com/api/v1/SHEET_ID"
fetch('https://sheetrest.com/api/v1/SHEET_ID', {
method: 'GET',
headers: {
accept: 'application/json',
'X-API-Token': 'YOUR_AUTH_TOKEN',
},
});