1

When I make a copy of a folder in smartsheet, is there a way to get the ID of the new folder?

What I have tried so far is this:

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)

This gives me a long response that looks like this:

{"folders": [{"id": 1261015317931908, "name": "Title Test Cell", "permalink": "permalink goes here"}], "id": 6664015456823172, "name": "Smartsheet Folder Destination", "permalink": "permalink goes here (I edited it)"}

How do I get just the id of the new folder?

adamcoolcat
  • 105
  • 7

1 Answers1

2

When you create a new folder (or copy from an existing folder), the response will include several attributes of the new folder, including the id. If you don't need the other attributes, just ignore them.

From the API docs:

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

So in Python, after you get your response:

folder_id = response.result.id
Software2
  • 2,358
  • 1
  • 18
  • 28
  • The response.id works for the get folder function. However, if I call folder_id = response.id directly after copying the new folder, I get the answer: AttributeError: 'Result' object has no attribute' – adamcoolcat Aug 01 '18 at 19:01
  • Whoops. `id` is inside `result`. Updated answer. (Take a look at the object in your debugger to see all the information an object contains.) – Software2 Aug 01 '18 at 19:12
  • Ah, I understand how the objects work now, thank you very much, I am new to python and will definitely try that debugger out, thank you very much! – adamcoolcat Aug 01 '18 at 19:19