Skip to content

Fall back to search by title#132

Open
JillRegan wants to merge 1 commit intomainfrom
jill/26-char
Open

Fall back to search by title#132
JillRegan wants to merge 1 commit intomainfrom
jill/26-char

Conversation

@JillRegan
Copy link
Copy Markdown

@JillRegan JillRegan commented Apr 1, 2026

Item id is 26-character lowercase alphanumeric shape but this can be the came for some item titles. get_item previously treated every such string as an id, so lookups by title could fail even though the API could resolve the item via the title filter.

This change tries get_item_by_id first when the string matches that shape, and on HTTP 404 falls back to get_item_by_title with the same string. Other errors (for example 401) are unchanged and are not treated as a title lookup.

Resolves: #80

Testing

  • Added test cases for this in src/tests/test_client_items.py
  • Manually tested by running locally and tested getting an item that had a title of 26 characters. Example:
from onepasswordconnectsdk import client

HOST = os.environ["OP_CONNECT_HOST"]
TOKEN = os.environ["OP_CONNECT_TOKEN"]
VAULT_ID = os.environ["OP_VAULT"]
ITEM_ID = "eh2nir3zc3g56ik4xeh7hinnrq"
ITEM_TITLE_26 = "abcdefghijklmnop1234567890"


def main() -> None:
    c = client.new_client(HOST, TOKEN)

    # 26-char string
    item_by_26 = c.get_item(ITEM_TITLE_26, VAULT_ID)
    print("26-char lookup ->", item_by_26.id, item_by_26.title)

    # Real item id
    item_by_id = c.get_item(ITEM_ID, VAULT_ID)
    print("by id          ->", item_by_id.id, item_by_id.title)

if __name__ == "__main__":
    main()

@JillRegan JillRegan marked this pull request as ready for review April 1, 2026 19:09
@JillRegan JillRegan requested review from bertrmz and rishiy15 April 2, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_item fails if pass item title of 26characters in length

2 participants