Access to multiple attachments from API call

63 views
Skip to first unread message

Parker Jackson

unread,
Mar 9, 2021, 7:07:47 PM3/9/21
to zotero-dev
Good Morning,

I have noticed recently that in the json from the API call to our Zotero database that only the first attachment of an item is listed with its attachment key even though the item has multiple attachments.  I know that it is the correct item as it has numchildren as 2.  Is there a way to get all children attachment keys from the parent item?

Thanks,

Dan Stillman

unread,
Mar 9, 2021, 7:08:38 PM3/9/21
to zoter...@googlegroups.com
Can you say the actual request you're making? (Don't include an API key.)

Parker Jackson

unread,
Mar 10, 2021, 1:05:57 AM3/10/21
to zotero-dev
We are using a wrapper that makes the call a little easier to make changeable but essentially the call is to "https://www.zotero.org/groups/<groupKey>/items/top".  We are using php and when using json_decode() on the return and putting it into a json file, we get json for all of the top level items in the database as expected, but only one attachment is listed for the items that have attachments even the ones with multiple.

Let me know if there is more info you need.

Thanks,

Dan Stillman

unread,
Mar 10, 2021, 1:21:27 AM3/10/21
to zoter...@googlegroups.com
On 3/10/21 1:05 AM, Parker Jackson wrote:
> We are using a wrapper that makes the call a little easier to make
> changeable but essentially the call is to
> "https://www.zotero.org/groups/<groupKey>/items/top".  We are using
> php and when using json_decode() on the return and putting it into a
> json file, we get json for all of the top level items in the database
> as expected, but only one attachment is listed for the items that have
> attachments even the ones with multiple.

I still don't know what response you're referring to. /top specifically
returns top-level items. It doesn't return child items.

If you're making some other request, you'd have to say what it is and
provide an example of the response you're getting.

Parker Jackson

unread,
Mar 10, 2021, 9:41:58 PM3/10/21
to zotero-dev
We are making a call to /top in order to get a response that lists the attachmentKey under each top level item.  We then use that attachment key to make further calls.  The problem that we are having with top level items with multiple attachments is that there is only reference to one attachment in this response.  

If you look in the included document,  this top level item has an item key of 4Q8L3Y8V,  it has one attachment listed with an attachmentKey of 8FCEB6WH.  There is another attachment in the database under this item with an attachmentKey of VSSG9IM6 but it is not found anywhere in the response.

Thanks,
example.txt

Dan Stillman

unread,
Mar 10, 2021, 11:42:47 PM3/10/21
to zoter...@googlegroups.com
On 3/10/21 9:41 PM, Parker Jackson wrote:
> We are making a call to /top in order to get a response that lists the
> attachmentKey under each top level item.  We then use that attachment
> key to make further calls.  The problem that we are having with top
> level items with multiple attachments is that there is only reference
> to one attachment in this response.
>
> If you look in the included document,  this top level item has an item
> key of 4Q8L3Y8V,  it has one attachment listed with an attachmentKey
> of 8FCEB6WH.  There is another attachment in the database under this
> item with an attachmentKey of VSSG9IM6 but it is not found anywhere in
> the response.

'attachmentKey' isn't something the API returns, to be clear. You seem
to be referring to `.links.attachment`, which gives you the "best"
attachment for an item — i.e., the same attachment you get if you
double-click on an item in Zotero. That's how the web library shows you
whether there's a PDF or snapshot and lets you open it without loading
all child items.

If you want child items, you have to actually request the child items.
See the `<userOrGroupPrefix>/items/<itemKey>/children` request in the
documentation:

https://www.zotero.org/support/dev/web_api/v3/basics#user_and_group_library_urls

Parker Jackson

unread,
Mar 11, 2021, 12:42:23 AM3/11/21
to zotero-dev
That's definitely what we needed.  Somehow must have missed it.

Thanks for your help

Reply all
Reply to author
Forward
0 new messages