How do I add linkInFromCell by REST API?

using Python SDK.


If I use add_row

it will tell me that this is not allowed.


If I use update_row, and with a random value (if value != null), it will return the following error.

"errorCode": 1110, "message": "cell.value must be null if cell.linkInFromCell is non-null."


If I use update_row, and with a value:null it will claim that value is missing.


Do anyone know how to use this API properly?

Answers

  • If I use update_row, and with a value:null it will claim the following:

    "errorCode": 1012, "message": "Required object attribute(s) are missing from your request: cell.value."


    I was not able to find proper way for this api to work.

  • Genevieve P.
    Genevieve P. Employee Admin

    Hi @Lilian T

    A CellLink object can only be added to an existing cell, so the cell.linkInFromCell attribute is not allowed when POSTing a new row to a sheet (as you've found).

    You are correct in using update_row instead of add_row. Additionally, you are correct in having value:null, see this section of the documentation: https://smartsheet-platform.github.io/api-docs/?python#update-cells

    "When creating a cell link, cell.value must be null (the data is pulled from the linked cell)."

    Keep in mind the following:

    "A cell may not contain both a hyperlink and a cell link, so hyperlink and linkInFromCell may never both be non-null at the same time."

    Did that help clarify how this feature works? Let me know if you're still receiving any errors!

    Cheers,

    Genevieve

  • Hi @Genevieve P

    Thanks a lot for getting back.

    I did use the update_row and added only linkInFromCell value, however it still gave the same error as "add_row" API.

    smartsheet.exceptions.ApiError: {"result": {"code": 1012, "errorCode": 1012, "message": "Required object attribute(s) are missing from your request: cell.value.", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "dbhpnyonitn5", "shouldRetry": false, "statusCode": 400}}


    I didn't have hyberlink value set in the cell value. (in Python)

    Idnew_row.cells = [
        {
            "columnId": [columnId],
            "linkInFromCell":{
                "columnId": [link_from_columnId],
                "rowId" [link_from_rowId],
                "sheetId": [link_from_sheetId]
            },
            "value": None
        }
    ]
    


  • Genevieve P.
    Genevieve P. Employee Admin

    Hi @Lilian T

    My apologies, I've looked into this further and by default the SDKs won't serialize a null property, so even though it is being set to None in this case, valuewon't be present in the JSON body.

    The provision created in the SDKs is to use an ExplicitNull.

    I have an example of this for you:

       def test_link_in_from_cell(self, smart_setup):
            smart = smart_setup['smart']
    ​
            sheet = smart_setup['sheet']
            row = smart.models.Row()
            row.to_bottom = True
            col_id = sheet.columns[0].id
            row.cells.append({
                'column_id': col_id,
                'value': 'abc123'
            })
    ​
            action = smart.Sheets.add_rows(sheet.id, [row])
            added_row = action.result[0]
    ​
            assert isinstance(added_row, smart.models.row.Row)
            assert action.request_response.status_code == 200
    ​
            sheet_b = smart_setup['sheet_b']
            cell_link = smart.models.CellLink()
            cell_link.sheet_id = sheet_b.id
            cell_link.row_id = sheet_b.rows[0].id
            cell_link.column_id = sheet_b.columns[0].id
    ​
            cell = smart.models.Cell()
            cell.column_id = col_id
            cell.link_in_from_cell = cell_link
            cell.value = smart.models.ExplicitNull()
    ​
            row = smart.models.Row()
            row.id = added_row.id
            row.cells.append(cell)
    ​
            action = smart.Sheets.update_rows(sheet.id, [row])
            assert action.request_response.status_code == 200
    ​
            action = smart.Sheets.delete_rows(sheet.id, [added_row.id])
            assert action.request_response.status_code == 200
    


    You may want to take a look at the discussions about this on the GitHub website, such as this one: updating row with cellLink()

    Let me know if this has worked for you!

    Genevieve

  • retry with ExplicitNull


    error message changed:

    smartsheet.exceptions.ApiError: {"result": {"code": 1032, "errorCode": 1032, "message": "The attribute(s) cell.linkInFromCell are not allowed for this operation.", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "gjtvl6uogub3", "shouldRetry": false, "statusCode": 400}}

    guess it's not possible to be used as an input for add_row API?

    retrying with update_row

  • from the documents (Cell Links)

    seems POSTing a new row is indeed not allowed.

    Creating or updating cell links via the cell.linkInFromCell attribute is a special operation. A given row or cell update operation may contain only link updates, or no link updates. Attempting to mix row/cell updates with cell link updates results in error code 1115. Additionally, a CellLink object can only be added to an existing cell, so the cell.linkInFromCell attribute is not allowed when POSTing a new row to a sheet.

  • update_rows() received the following error:

    smartsheet.exceptions.ApiError: {"result": {"code": 4000, "errorCode": 4000, "message": "An unexpected error has occurred. Please contact the Support team at https://help.smartsheet.com/contact for assistance.", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "7tc8g7ifmdqn", "shouldRetry": false, "statusCode": 500}}

    payload didn't change at all. will investigate further later why.