[SOLVED] Accessing Attachments via API
Not sure where to post this, so apologies if it should go somewhere else.
I'm trying to figure out the best way to get an item's attachments (e.g. PDF files) using the API (with cURL and AJAX). Attachments appear to be listed either (a) under all items or (b) as a particular item's children. They don't seem to be listed in collection or tag item sets. So, as far as I can figure, I either:
(a) request all items and look for "zapi:itemType" of type attachment whose "up" link is the citation item (which isn't feasible when you have lots of items because the 99 item limit, not to mention load times), or ...
(b) make a separate request per item and check its children to see if there's any that are an attachment (which isn't great because in a huge set of items you'd have to make just as many requests as there are items, e.g. if my collection has 50 items I'll have to make 50 requests to look at each item's children. I can't NOT request per item because the item properties give NO indication whether the item has children /an attachment). Edit: Oops! You can get the number of children from the "zapi:numChildren".
Neither of these options seems very good. Is there another way that I'm just not seeing? If not, I'd like to make a feature request: either give items a property, e.g. "children" that shows the number of children they have (or just if they have any), or have attachment items show up under collection and tag sets (perhaps "tag" attachments with the collection and tag(s) of their parents).
Any ideas and help are much appreciated.
I'm trying to figure out the best way to get an item's attachments (e.g. PDF files) using the API (with cURL and AJAX). Attachments appear to be listed either (a) under all items or (b) as a particular item's children. They don't seem to be listed in collection or tag item sets. So, as far as I can figure, I either:
(a) request all items and look for "zapi:itemType" of type attachment whose "up" link is the citation item (which isn't feasible when you have lots of items because the 99 item limit, not to mention load times), or ...
(b) make a separate request per item and check its children to see if there's any that are an attachment (which isn't great because in a huge set of items you'd have to make just as many requests as there are items, e.g. if my collection has 50 items I'll have to make 50 requests to look at each item's children. I can't NOT request per item because the item properties give NO indication whether the item has children /an attachment). Edit: Oops! You can get the number of children from the "zapi:numChildren".
Neither of these options seems very good. Is there another way that I'm just not seeing? If not, I'd like to make a feature request: either give items a property, e.g. "children" that shows the number of children they have (or just if they have any), or have attachment items show up under collection and tag sets (perhaps "tag" attachments with the collection and tag(s) of their parents).
Any ideas and help are much appreciated.
<zapi:numChildren>1</zapi:numChildren>
I didn't know you could go with a "content=json" parameter, though. On the API documentation (http://www.zotero.org/support/dev/server_api) it says the values can be: “none”, “html”, “bib”. How'd you know about the "json" option?
I just went ahead and added it to the main docs.
In case I want to know if an item has a pdf file or even how many, numChildren does not help much.
Then I should go retrieve all its children, right?