Deleting items via Zotero API

69 views
Skip to first unread message

Frank Bennett

unread,
Feb 20, 2020, 1:26:24 AM2/20/20
to zotero-dev
I've gotten slightly confused in the docs re deleting items via the Zotero API, and I'd like to confirm that I understand things correctly:


Testing with a single item, I fetched the attachment metadata, pulled out the item key and version, and fed that back to a DELETE request. The request failed with a 412 error ("The library has changed since the specified version"). As options to the call:

// ?itemKey=43BYNQ7L
// maxVersion: 2505
{
  "method": "DELETE",
  "headers": {
    "content-type": "application/json",
    "Zotero-API-Key": "...",
    "If-Unmodified-Since-Version": "2505"
  },
  "url": "?itemKey=43BYNQ7L",
  "responseType": "json"
}
Error: Request failed with status code 412

I tried a few other values: (1) the [much lower] library version value; and (2) the version incremented by one [so 2506]. Both also failed with 412.

Then, just for fun, I tried with a version value of 10000 -- and the delete succeeded.

Looking at that result, which initially seemed really weird, I thought to check the version of the _parent_ item, and that was "2749." More than "2505", and less than "10000," it looks like that might have been the value I was fishing for.

So what I _think_ this may mean is that the modification threshold value is the version of the immediate container? So for a top-level item, that would be the containing library ("5" in this case); and for an attachment, it would be the parent item serving as its "container."

Is that a correct read on the behavior?

(If so, the docs should maybe be amended on that point to avoid confusion.)

Frank

Dan Stillman

unread,
Feb 20, 2020, 3:49:36 PM2/20/20
to zoter...@googlegroups.com
On 2/20/20 1:26 AM, Frank Bennett wrote:
> I've gotten slightly confused in the docs re deleting items via the
> Zotero API, and I'd like to confirm that I understand things correctly:
>
> https://www.zotero.org/support/dev/web_api/v3/write_requests#deleting_multiple_items
>
> Testing with a single item, I fetched the attachment metadata, pulled
> out the item key and version, and fed that back to a DELETE request.
> The request failed with a 412 error ("The library has changed since
> the specified version"). As options to the call:
>
> // ?itemKey=43BYNQ7L
> // maxVersion: 2505
> {
>   "method": "DELETE",
>   "headers": {
>     "content-type": "application/json",
>     "Zotero-API-Key": "...",
>     "If-Unmodified-Since-Version": "2505"
>   },
>   "url": "?itemKey=43BYNQ7L",
>   "baseURL": "https://api.zotero.org/groups/2318535/items/",
>   "responseType": "json"
> }
> Error: Request failed with status code 412
>
> […]
>
> So what I _think_ this may mean is that the modification threshold
> value is the version of the immediate container? So for a top-level
> item, that would be the containing library ("5" in this case); and for
> an attachment, it would be the parent item serving as its "container."
>
> Is that a correct read on the behavior?

No, nothing to do with the parent item.

It sounds like you're passing the item version to the multi-object
DELETE request instead of the library version.

For single-object requests,
Last-Modified-Version/If-Unmodified-Since-Version are for the version of
the object. For multi-object requests, they apply to the library as a
whole. (That's why the error message says that the library has changed
since the specified version, not that the item has changed.) The fact
that you're passing only a single item key to a multi-item endpoint is
immaterial.

The various version properties are explained in detail on the Syncing
page [1], but I'll see if I can clarify things on the Write Requests page.

[1] https://www.zotero.org/support/dev/web_api/v3/syncing#version_numbers
Reply all
Reply to author
Forward
0 new messages