【问题标题】:How do I get the ID of a new folder/sheet that I have created from a copy?如何获取从副本创建的新文件夹/工作表的 ID?
【发布时间】:2018-08-01 15:08:27
【问题描述】:

当我在 smartsheet 中复制文件夹时,有没有办法获取新文件夹的 ID?

到目前为止我尝试过的是:

inc_list = ['all'] # you can add other parameters here, separated by a comma
 response = ss_client.Folders.copy_folder(
 folderID,                           # folder_id
 ss_client.models.ContainerDestination({
'destination_id': destinationID,
'destination_type': 'folder',
'new_name': cellValue
}),
include=inc_list
)

folder = ss_client.Folders.get_folder(
destinationID)       # folder_id

print (folder)

这给了我一个看起来像这样的长响应:

{"folders": [{"id": 1261015317931908, "name": "Title Test Cell", "permalink": "permalink goes here"}], "id": 6664015456823172, "name": "Smartsheet文件夹目的地”,“永久链接”:“永久链接在这里(我编辑过)”}

如何只获取新文件夹的 ID?

【问题讨论】:

    标签: python api smartsheet-api smartsheet-api-2.0


    【解决方案1】:

    当您创建新文件夹(或从现有文件夹复制)时,响应将包含新文件夹的多个属性,包括 id。如果您不需要其他属性,请忽略它们。

    来自API docs

    {
      "message": "SUCCESS",    
      "resultCode": 0,
      "result": {
        "id": 7116448184199044,
        "name": "newFolderName",
        "permalink": "https://{base_url}?lx=lB0JaOh6AX1wGwqxsQIMaA"
      }
    }
    

    所以在 Python 中,在您收到回复后:

    folder_id = response.result.id
    

    【讨论】:

    • response.id 适用于获取文件夹功能。但是,如果我在复制新文件夹后直接调用 folder_id = response.id,我会得到答案:AttributeError: 'Result' object has no attribute'
    • 哎呀。 idresult 内。更新了答案。 (查看调试器中的对象以查看对象包含的所有信息。)
    • 啊,我现在了解对象的工作原理了,非常感谢,我是 python 新手,一定会尝试使用该调试器,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 2019-01-10
    • 2016-03-25
    • 1970-01-01
    • 2012-05-13
    相关资源
    最近更新 更多