File object in Python SDK
Answered
File objects in the Python Box SDK are populated with different properties depending on how they are created. For example, if I get a file using client.file and request its content_created_at property, I get an error. For example,
aFile = client.file(my_id)
print(aFile.content_created_at)
gives me
KeyError: 'content_created_at'
However, a search which is verified to retrieve the same document
aFiles = client.search(my_doc_name,limit=100,offset=0, result_type="file", content_types=["name"]) for aFile in aFiles: if(aFile.object_id == str(my_id)): print(aFile.content_created_at)
gives me a successful result (which the forum software seems to believe is a phone number, but you get the idea):
20***phone number removed for privacy***T10:34:***phone number removed for privacy***:00
Can anyone explain to me
- why these results are different, and
- how I can get the content_created_at value for a file that I have retrieved based on its ID?
Thanks,
Peter
-
Hi,
Many of the Client methods do not make API calls directly. Client.file(), Client.folder(), etc. are examples of this. Instead, they give you an empty object which is configured to make API calls that are rooted at that object. If I wanted to delete a folder, I could call client.file(my_id).delete(). If I wanted to rename it, I'd call client.file(my_id).rename(). In your case, you just want to GET information, so you should do file = client.file(my_id).get(). After that, you should be able to do file.content_created_at.
Whereas Client.search() actually makes the search API call directly, which is why the object you get from there already has the data you want.
Please sign in to leave a comment.
Comments
2 comments