Handle Item Move to Folder Error

1505
2
Jump to solution
10-17-2019 06:54 AM
KarenRobine
Frequent Contributor

I am attempting to move an item to a specific folder (using Python API, NOT Juypter). I don't see anything in the API to check if a folder exists. So according to the API:

move(folder, owner=None)

Moves this item to the folder with the given name.

ArgumentDescription
folderRequired string. The name of the folder to move the item to. Use ‘/’ for the root folder. For other folders, pass in the folder name as a string, or a dictionary containing the folder ID, such as the dictionary obtained from the folders property.
ownerOptional string or Owner object. The name of the user to move to.
Returns:A json object like the following: {“success”: true | false,
”itemId”: “<item id>”, “owner”: “<owner username>”, “folder”: “<folder id>”}

I'm trying to figure out how to capture the return object.  I've wrapped it in a Try/Catch but that doesn't seem to work.  It always gets to the next line but I get the console message, Folder not found for given owner.

If I do:

objMoved = myItem.move(folder="whatever")

objMoved is always None

What's the "best practice" way to get the results? 

0 Kudos
1 Solution

Accepted Solutions
KarenRobine
Frequent Contributor

The following code solves my issue:

objMoved = newmap.move(folder=configStore.folder)  #folder not found for given owner message if it doesnt move it.
print(objMoved)
if (objMoved is None) or \
        (objMoved is not None and 'success' in objMoved and not objMoved['success']):
    print("we flunked moving the object")

    newmap.delete(force=False, dry_run=False)
    sys.exit(
        "ERROR: Unable to move the item with ItemID {0} to the folder, {1}. ".format(
            id, configStore.folder))

View solution in original post

2 Replies
KarenRobine
Frequent Contributor

The following code solves my issue:

objMoved = newmap.move(folder=configStore.folder)  #folder not found for given owner message if it doesnt move it.
print(objMoved)
if (objMoved is None) or \
        (objMoved is not None and 'success' in objMoved and not objMoved['success']):
    print("we flunked moving the object")

    newmap.delete(force=False, dry_run=False)
    sys.exit(
        "ERROR: Unable to move the item with ItemID {0} to the folder, {1}. ".format(
            id, configStore.folder))
AndresCastillo
MVP Regular Contributor

Thank you for posting your solution.

0 Kudos