How to get sheet owner information

I am trying to get sheet owner information through python SDK.

But I am getting "None" for owner name.

Am I doing something wrong here?

Best Answer

  • Lee Joramo
    Lee Joramo ✭✭✭✭✭✭
    edited 01/28/25 Answer ✓

    Paul is correct. It looks like we now need to grab the sheet shares to get the owner information.

    Here is a python function that will get the owner of a sheet by sheet ID:

    def get_owner_from_shares(sheetId):
        # exclude workspace shares so we don't get the owner of the workspace 
        response = smartSheetClient.Sheets.list_shares(
            sheetId, include_all=True, include_workspace_shares=False
        )
        data = response.to_dict()
    
        owner = None
        for item in data["result"]:
            if item.get("accessLevel") == "OWNER":
                owner = item
                break
        return owner
    
    
    

    I have been trying to track changes in the Smartsheet API, but I missed this change. I am pretty sure that this get sheet call used to return the owner information up to sometime in December.

    While Smartsheet updates their API documentation, they do not tell you what changed in the documentation. Which is a MAJOR pain point for developers. (I discussed this with them at the last conference.)

Answers

  • Lee Joramo
    Lee Joramo ✭✭✭✭✭✭

    I am writing this quickly as I am about to leave the office. Hopefully, it will get you on track. I can dig deeper tomorrow. Hopefully, I am not incorrectly remembering this issue. I know ran into something like this last year.

    I believe this is an undocumented change in the API where sheet.owner now returns None

    You will have to take the sheet.ownerId from your get_sheet call and then make an API call to getUser and provided the ownerId. Then you should be provided the email address.

  • Hi Lee,
    Thanks for your reply.

    Unfortunately, sheet.owner_id also gives me "None" in this case.

    Any advice?

  • Paul Newcome
    Paul Newcome Community Champion

    If the get_sheet doesn't work for at least retrieving the owner, getting the sheet shares should do the trick.

  • @Paul Newcome

    Would you mind sharing the code?

  • Lee Joramo
    Lee Joramo ✭✭✭✭✭✭
    edited 01/28/25 Answer ✓

    Paul is correct. It looks like we now need to grab the sheet shares to get the owner information.

    Here is a python function that will get the owner of a sheet by sheet ID:

    def get_owner_from_shares(sheetId):
        # exclude workspace shares so we don't get the owner of the workspace 
        response = smartSheetClient.Sheets.list_shares(
            sheetId, include_all=True, include_workspace_shares=False
        )
        data = response.to_dict()
    
        owner = None
        for item in data["result"]:
            if item.get("accessLevel") == "OWNER":
                owner = item
                break
        return owner
    
    
    

    I have been trying to track changes in the Smartsheet API, but I missed this change. I am pretty sure that this get sheet call used to return the owner information up to sometime in December.

    While Smartsheet updates their API documentation, they do not tell you what changed in the documentation. Which is a MAJOR pain point for developers. (I discussed this with them at the last conference.)

  • Lee Joramo
    Lee Joramo ✭✭✭✭✭✭
    edited 01/28/25

    Sorry for that last block of text with the OWNER user object. I accidentally pasted it in my comment, and the forum comment editor will not let me delete it. (I even dropped into the browsers inspector and tried to remove it from the DOM.)

    … and I tried to edit it in Firefox, and was able to delete it.