Get itemkey from attachmentkey

edited March 17, 2023
I wanna achive the function that jump from local PDF to item in zotero.

Attachmentkey can get from local folder, like 8KH8HZAR, then can reach to zotero via zotero://select/library/items/[attachmentkey]. But selection is attachment instead of item.

Is there any way to obtain itemkey from attachmentkey?
  • You can use the Zutilo add-on to get the zotero select link for an item.
  • edited March 17, 2023
    Thanks for your reply. But it may not works for me cause I need to get the itemkey directly before selection. Zutilo just can export link of selection, also, I selected a attachment and tried copy select item links and copy zotero URIS via Zutilo, but get the attachment link instead of item link.

    Is there any .js or other way to get itemkey from attachmentkey?
  • You'll need to give a more detailed description of what you're after and in what context then. If you just post here I assume GUI options are what you're looking for.
  • OK. Simply, I need the function mostly like "show in library" when using Zotero PDF viewer. But I also often use local PDF viewer (like PDF Expert) for some cases.

    So, I need to set my workflow of jump from current PDF in PDF Expert to Zotero:
    1. (Finished) Get the folder of current PDF (attachmentkey) via PDF Expert;
    2. Transform the attachmentkey to itemkey;
    3. Jump from PDF Expert to Zotero using zotero://select/library/items/[itemkey].

    Step 2 is what I want to ask for help.
  • edited March 18, 2023
    var attachmentItem = await Zotero.Items.getByLibraryAndKeyAsync(
    Zotero.Libraries.userLibraryID,
    attachmentKey
    );
    var itemKey = attachmentItem.parentKey;
  • That's it! Many thanks @dstillman.
Sign In or Register to comment.