1Password / connect-sdk-python

Python SDK for 1Password Connect
https://developer.1password.com/docs/connect
MIT License
200 stars 31 forks source link

How does one determine a fileId/documentId using the python SDK? #36

Closed irons closed 2 years ago

irons commented 2 years ago

Your environment

Built from main, commit 678d60 from November 9th (because the document support committed in October hasn't been released yet)

Connect Server Version: 1.5.0

OS: macOS 11.6.3

Python Version: 3.9.10

What happened?

The API for download_file, consistent with the library's other file APIs, expects a file ID, an item ID, and a vault ID.

Starting from a vault name and an item name, I can determine the vault ID and the item ID, but the output of get_item doesn't include a file ID. It is included in the CLI output of get item, under a different name:

op get item <document-item-id> --vault <vault-id> | jq -r .details.documentAttributes.documentId

The same documentId is shown via the Copy JSON command in the Mac app, and when I feed that identifier to the download_file API, it succeeds. But it isn't useful if I can't programmatically determine the ID, and I am not seeing any way to do that.

What did you expect to happen?

I should be able to use the python library, vault access, and knowledge of a file's name to access the file.

Notes & Logs

Here's the output of get_item:

{'category': 'DOCUMENT',
 'created_at': datetime.datetime(2022, 2, 8, 0, 10, 12, tzinfo=tzutc()),
 'favorite': False,
 'fields': [{'entropy': None,
             'generate': False,
             'id': 'notesPlain',
             'label': 'notesPlain',
             'purpose': 'NOTES',
             'section': None,
             'type': 'STRING',
             'value': None}],
 'id': 'a7qk2fixrbalrifv3heqcxntyi',
 'last_edited_by': 'FRAQH4JNUJG6XPMLJO2GVA72T4',
 'sections': None,
 'tags': None,
 'title': 'redacted-file-title',
 'trashed': False,
 'updated_at': datetime.datetime(2022, 2, 8, 0, 10, 13, tzinfo=tzutc()),
 'urls': None,
 'vault': {'id': 'jm4ixdhaljgodbzehdxjxxwagy'},
 'version': 1}

Thanks for your time.

jillianwilson commented 2 years ago

Hi there!

Looks like the solution to this is not currently documented, so thank you for bringing this issue to our attention. To get data on files (including the file ids) for an item you will need to use the get_files method.

For example the following:

client.get_files(<some_item_id>, <some_vault_id>)

Will return an object of the following format:

{
        'id': 'str',
        'name': 'str',
        'size': 'int',
        'content_path': 'str',
}

I'll update the README to reflect this information. Please let me know if this resolves your issue.

irons commented 2 years ago

Thank you, yes.