How do I add linkInFromCell by REST API?

01/22/21
Answered - Pending Review

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.

  • 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
        }
    ]
    


  • 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

Sign In or Register to comment.