I've been through the documentation of the Google Sheets API v4 and couldn't find a way to read data from a named range. I'm using Python, specifically, and looking for something along the lines of:
named_range = 'My Beautiful Range'
service = build('sheets', 'v4', credentials=creds)
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=my_id,
namedRange=named_range).execute()
values = result.get('values', [])
Is there such an API?
Yes, both spreadsheets.values.get and spreadsheets.get accepts named ranges as their range parameter.
Just keep in mind that your named ranges should be valid and existing in the spreadsheet that you are trying to access.
Valid Range Names:
Sample Code:
named_range = 'MyBeautifulRange'
result = sheet.values().get(spreadsheetId=my_id,
range=named_range).execute()
values = result.get('values', [])
Sample Sheet:

Sample spreadsheets.values.get request using API explorer:

Sample Response Body:
{
"range": "Sheet1!A1:B3",
"majorDimension": "ROWS",
"values": [
[
"A1",
"B1"
],
[
"A2",
"B2"
],
[
"A3",
"B3"
]
]
}
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