The documentation for the hyperlink field is "A hyperlink this cell points to, if any. This field is read-only. (To set it, use a =HYPERLINK formula.)". You're still setting the hyperlink field (although you're attempting to set it to a formula). That won't work, because the field is read only. To set a formula, set a value in userEnteredValue.formulaValue. That will set a formula on the server, and the hyperlink field will be populated as a result.

Answer from Sam Berlin on Stack Overflow
Top answer
1 of 2
8

I figured it out:

def addHyperlink(self, hyperlink, text, sheetId, rowIndex, colIndex):
    requests = []
    requests.append({
        "updateCells": {
            "rows": [
                {
                    "values": [{
                        "userEnteredValue": {
                            "formulaValue":"=HYPERLINK({},{})".format(hyperlink, text) 
                        }
                    }]
                }
            ],
            "fields": "userEnteredValue",
            "start": {
                "sheetId": sheetId,
                "rowIndex": rowIndex,
                "columnIndex": colIndex
            }
        }})
    body = {
        "requests": requests
    }
    request = self.service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body)
    return request.execute()
2 of 2
-1

links not worked!!! But add like note)

def addHyperlink(self, uri_1, summa_, sheetId, rowIndex, colIndex):
    requests = []
    requests.append({
        "updateCells": {
            "rows": [{
                "values": [{
                    'userEnteredValue': {'numberValue': float(summa_)}, #
                    'effectiveValue': {'numberValue': float(summa_)},
                    'formattedValue': "р."+summa_,
                    'userEnteredFormat': {
                        'numberFormat': {'type': 'NUMBER', 'pattern': '[$р.-419]#,##0.00'},
                        'backgroundColor': {'red': 1, 'green': 1, 'blue': 0.6}, 'borders': {
                            'top': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}},
                            'bottom': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}},
                            'left': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}},
                            'right': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}}},
                        'horizontalAlignment': 'RIGHT', 'verticalAlignment': 'BOTTOM',
                        'textFormat': {
                            'foregroundColor': {'red': 0.06666667, 'green': 0.33333334, 'blue': 0.8},
                            'fontFamily': 'Arial', 'underline': True,
                            'foregroundColorStyle': {'rgbColor': {'red': 0.06666667, 'green': 0.33333334, 'blue': 0.8}},
                            'link': {'uri': uri_1}
                        },
                        'hyperlinkDisplayType': 'LINKED','backgroundColorStyle': {'rgbColor': {'red': 1, 'green': 1, 'blue': 0.6}}
                    }
                    ,                            'hyperlink': uri_1 , 'note': uri_1,
                }
                ]
            }], "fields": '*', "start": {
                "sheetId": sheetId, "rowIndex": rowIndex, "columnIndex": colIndex}}})
    body = {
        "requests": requests}
    request = self.service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body)
    return request.execute()
Discussions

How to Get Hyperlinks Using Google Sheets API v4 - Stack Overflow
I am trying to access a hyperlink using the v4 API ValueRenderOption param (valueRenderOption=FORMULA). I have tried with both python's gsheets and cURL. Either way, I cannot seem to get the formul... More on stackoverflow.com
🌐 stackoverflow.com
How to Insert hyperlink in a spreadsheet file using Google Spreadsheet API - Stack Overflow
You want to create new Spreadsheet including the cell values using the method of spreadsheets.create in Sheets API. From your request body, I imaged like above. You want to put the cell values which have the hyperlink when new Spreadsheet is created. More on stackoverflow.com
🌐 stackoverflow.com
python - Get hyperlink from a cell in google Sheet api V4 - Stack Overflow
Although I'm not sure whether this ... for Google APIs. 2020-09-02T22:36:49.787Z+00:00 ... The values for fields is a path within the returned JSON. However, the default spreadsheet.get() function does not return all the data, so it's far from clear where the hyperlink value comes ... More on stackoverflow.com
🌐 stackoverflow.com
node.js - Extract url from hyperlink using google sheets api - Stack Overflow
I have several columns in a google sheet containing only hyperlinks and need to be able to extract the url from the string. I request the sheet using googleapis npm package and the hyperlinks come ... More on stackoverflow.com
🌐 stackoverflow.com
December 3, 2018
🌐
Reddit
reddit.com › r/googlesheets › accessing hyperlink in google sheets cell using api v4 w/ python
r/googlesheets on Reddit: Accessing hyperlink in Google Sheets cell using API V4 w/ Python
March 9, 2022 -

Thanks for looking.

I am trying to read the hyperlinks from a variety of cells in my sheet. I have seen a variety of answers (here and here) to this question using the following syntax, but I can't get it to work.

import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
from googleapiclient import discovery
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]

creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json",scope)
client = gspread.authorize(creds)
service = discovery.build('sheets', 'v4', credentials=creds)

sheetID = "Sealed League Score Sheet"
RANGE_NAME = ['Score Sheet!D3:D3']
FIELDS = "sheets/data/rowData/values/hyperlink"

request = service.spreadsheets().get(spreadsheetId = sheetID, ranges = RANGE_NAME, includeGridData = 'true', fields = FIELDS)
response = request.execute() 

I just started using Sheets today so I could be missing some obvious core element required to actually perform these actions. For example, my suspicion is that the service
declaration doesn't make any sense and is the root of the problem, but I've been struggling to find any information on why you even need it. I get an HTTP 404 error in my console, which I'm assuming means it's not even looking in the right place to begin with

I was able to write and read to my spreadsheet using methods like playerName = client.open(sheetID).worksheet("Score Sheet").cell(1,1)
, but the Hyperlink issue has me seriously stumped

Top answer
1 of 1
5

I believe your goal as follows.

  • You want to retrieve a hyperlink which was set to a cell on Google Spreadsheet.

In this case, in the current stage, the hyperlink can be retrieved using the method of "spreadsheets.get" in Sheets API. And, it is required to use the field parameter for this request. By this, the hyperlink can be retrieved. The sample curl command is as follows.

As the sample situation, it supposes that the URL is set to a cell "A1" of "Sheet1" in Google Spreadsheet.

Sample curl command:

curl \
  'https://sheets.googleapis.com/v4/spreadsheets/[SPREADSHEETID]?ranges=Sheet1!A1&fields=sheets(data(rowData(values(hyperlink))))' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed
Result:
{
  "sheets": [
    {
      "data": [
        {
          "rowData": [
            {
              "values": [
                {
                  "hyperlink": "https://example.com/"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

For gspread:

At gspread, requests library is used as follows. The access token is retrieved from credentials of gspread.authorize(credentials).

gc = gspread.authorize(credentials)
access_token = credentials.access_token
url = 'https://sheets.googleapis.com/v4/spreadsheets/[SPREADSHEETID]?ranges=Sheet1!A1&fields=sheets(data(rowData(values(hyperlink))))'
res = requests.get(url, headers={'Authorization': 'Bearer ' + access_token})
print(res.json())
Result:
{'sheets': [{'data': [{'rowData': [{'values': [{'hyperlink': 'https://example.com/'}]}]}]}]}

Note:

  • In this sample, sheets(data(rowData(values(hyperlink)))) is used as fields. About this, you can also use sheets. In this case, other values are included in the response values.
  • At the sample, Sheet1!A1 is used as the range. So please modify this range for your actual situation.
  • In the current stage, when a hyperlinks is set to a part of texts in a cell and the several hyperlinks are set to a cell, unfortunately, those cannot be directly retrieved using Sheets API. At that time, as the current workaround, it is required to use Google Apps Script. Ref Please be careful this.

References:

  • Method: spreadsheets.get
🌐
Google Support
support.google.com › docs › answer › 3093313
HYPERLINK - Google Docs Editors Help
Creates a hyperlink inside a cell. Sample Usage HYPERLINK("http://www.google.com/","Google") Syntax HYPERLINK(url, [link_label]) url - The full URL of the link location enclosed in quotati
🌐
GitHub
gist.github.com › tanaikech › b18c0189a5d0266a849090fdbe6750a5
Workaround: Putting Multiple Hyperlinks to a Cell using Sheets API · GitHub
Recently, at Spreadsheet service, the multiple hyperlinks got to be able to be put to a cell. Ref In this case, it can be achieved using RichTextValue. On the other hand, at Sheets API, in the current stage, there are no methods for directly putting the multiple hyperlinks to a cell.
Find elsewhere
🌐
tanaike
tanaikech.github.io › home › "putting multiple hyperlinks to a cell using sheets api with google apps script and node.js"
Putting Multiple Hyperlinks to a Cell using Sheets API with Google Apps Script and Node.js | tanaike - Google Apps Script, Gemini API, and Developer Tips
October 27, 2022 - const obj = [ [ { stringValue: "sample link1 sample link2 sample", links: [ { value: "link1", uri: "https://www.google.com/" }, { value: "link2", uri: "https://tanaikech.github.io/" }, ], }, { stringValue: "link1", links: [{ value: "link1", uri: "https://www.google.com/" }], }, ], ]; const resource = { requests: [ { updateCells: { rows: obj.map((row) => ({ values: row.map(({ stringValue, links }) => ({ userEnteredValue: { stringValue }, textFormatRuns: links.reduce((ar, { value, uri }) => { const temp = stringValue.indexOf(value); if (temp != -1) { ar.push({ startIndex: temp, format: { link: {
🌐
GitHub
gist.github.com › tanaikech › 4c27bf8d1948a5dfa5b0e53ce88c6d30
Putting Multiple Hyperlinks to a Cell using Sheets API with Google Apps Script and Node.js · GitHub
// Please set the text and the hyperlinks. const obj = [ [ { stringValue: "sample link1 sample link2 sample", links: [ { value: "link1", uri: "https://www.google.com/" }, { value: "link2", uri: "https://tanaikech.github.io/" }, ], }, { stringValue: "link1", links: [{ value: "link1", uri: "https://www.google.com/" }], }, ], ]; const requests = [ { updateCells: { rows: obj.map((row) => ({ values: row.map(({ stringValue, links }) => ({ userEnteredValue: { stringValue }, textFormatRuns: links.reduce((ar, { value, uri }) => { const temp = stringValue.indexOf(value); if (temp != -1) { ar.push({ star
🌐
Google
developers.google.com › google workspace › google sheets › cells
Cells | Google Sheets | Google for Developers
September 3, 2024 - If not specified, the hyperlink is linked. The rotation applied to text in a cell. A run of a text format. The format of this run continues until the start index of the next run. When updating, all fields must be set. A data validation rule. A data source table, which allows the user to import a static table of data from the DataSource into Sheets...
🌐
Stack Overflow
stackoverflow.com › questions › 53602409 › extract-url-from-hyperlink-using-google-sheets-api
node.js - Extract url from hyperlink using google sheets api - Stack Overflow
December 3, 2018 - Figured it out, just set the valueRenderOption to 'FORMULA' and returns as =HYPERLINK('someurl.com', 'Display Text') https://developers.google.com/sheets/api/reference/rest/v4/ValueRenderOption#ENUM_VALUES.FORMATTED_VALUE
🌐
Simular
simular.ai › workflow › how-to-master-google-sheets-hyperlinks-practical-guide
How to master Google Sheets hyperlinks: practical guide
April 7, 2026 - Action: Update the row with either a raw URL or a full =HYPERLINK() formula. ... Pros: Great for small automations, no engineering required. Cons: Each run costs tasks/operations; debugging at scale can be painful; logic lives outside the sheet. Official Google Sheets API docs (for tools that integrate via API): https://developers.google.com/sheets/api
🌐
GitHub
github.com › googleapis › google-api-php-client › issues › 2475
fetch URL of the hyperlink from the cell using spreadsheets API · Issue #2475 · googleapis/google-api-php-client
July 7, 2023 - Hello, I need te fetch the data from the Google spreadsheets via API. But my cells contain hyperlinks. When I fetch the data in the response I receive only labels of the hyperlink. How to get URIs too? ... api: sheetsIssues related to the Sheets API API.Issues related to the Sheets API API.priority: p3Desirable enhancement or fix.
Author   googleapis
🌐
Stack Overflow
stackoverflow.com › questions › 64874341 › getting-hyperlink-from-cell-in-google-sheets-api-python
Getting hyperlink from cell in google sheets API python - Stack Overflow
# Call the Sheets API sheet = service.spreadsheets() ####################################################################### sheetName = title result = sheet.values().get(spreadsheetId='SpreadsheetId', range=sheetName).execute() values = result.get('values', []) resultLink = sheet.values().get(spreadsheetId='SpreadsheetId', range=sheetName,fields="sheets/data/rowData/values/hyperlink").execute() valuesLink = resultLink.get('values', [])
🌐
Stack Overflow
stackoverflow.com › questions › 40612615 › how-to-fetch-the-hyperlink-from-google-sheets
How to fetch the Hyperlink from Google Sheets
You need to set the valueRenderOption parameter in your request. More details about this are here: https://developers.google.com/sheets/api/reference/rest/v4/ValueRenderOption. To get the HYPERLINK, you need to set the value as FORMULA.
🌐
Google Support
support.google.com › docs › thread › 134824486 › sheets-certain-cells-not-accepting-hyperlinks
Sheets certain cells not accepting hyperlinks - Google Docs Editors Community
Skip to main content · Google Docs Editors Help · Sign in · Google Help · Help Center · Community · Google Docs Editors · Terms of Service · Submit feedback · Send feedback on