Is it possible to execute queries on spreadsheets using Google Query Language in gspread API? I was wandering if we can use this API call to execute these queries.
I believe your goal as follows.
requests
library is used, the Query language can be used.
When above points are reflected to a script, it becomes as follows.
In this case, the access token is retrieved from credentials
of client = gspread.authorize(credentials)
for using gspread.
client = gspread.authorize(credentials) # Here, please use your authorization script for using gspread.
spreadsheetId = '###' # Please set the Spreadsheet ID.
sheetName = 'Sheet1' # Please set the sheet name.
query = 'select A where B>=5000' # This is from your sample query.
url = 'https://docs.google.com/spreadsheets/d/' + spreadsheetId + '/gviz/tq?sheet=' + sheetName + '&tqx=out:csv&tq=' + urllib.parse.quote(query)
res = requests.get(url, headers={'Authorization': 'Bearer ' + credentials.access_token})
print(res.text)
import urllib.parse
and import requests
are also used.url = 'https://docs.google.com/spreadsheets/d/' + spreadsheetId + '/gviz/tq?sheet=' + sheetName + '&tqx=out:csv&tq=' + urllib.parse.quote(query)
to url = 'https://docs.google.com/spreadsheets/d/' + spreadsheetId + '/gviz/tq?gid=' + sheetId + '&tqx=out:csv&tq=' + urllib.parse.quote(query)
res = requests.get(url)
.