PATCH api request no changes

Hi I’m trying to make a PATCH request, but it’s not changing the item.

This is the json I’m trying to PATCH to https://nfpl.historicniagara.ca/api/items/89025

{
"dcterms:created":{
"type":"literal",
"property_id":19,
"property_label":"Date Created",
"is_public":true,
"@value":"2002-01-01 12:00:00"
},
"dcterms:modified":{
"type":"literal",
"property_id":24,
"property_label":"Date Modified",
"is_public":true,
"@value":"2005-01-20 11:23:41"
}
}

I’m getting no errors, it just fails. I originally wanted to import this data as timestamp, but that was having the same issue, so I thought this way might be easier. Maybe there’s a way to turn on additional logging?

Could you share some more about how you are submitting the PATCH to the API? cURL, Postman, other?

Here’s another thread discussing the proper syntax for PATCHing metadata via the Omeka S API. The JSON you’ve given appears correct, with the possible exception of enclosing brackets (this is where it would be helpful to see your full API request).

Thanks for replying. I’m using curl in a php script, and far as I could tell, the person in that post didn’t get any error messages.

here’s the script I’m using if that helps at all;

<?php

$url = 'https://nfpl.historicniagara.ca/api/items/';
$authentication = '?key_identity=yyyyyyy&key_credential=xxxxxx';

$itemID = 89025;
$createDate = "2002-01-01 12:00:00";
$modifiedDate = "2005-01-20 11:23:41";

$createDateArray["type"] = "literal";//"numeric:timestamp";
$createDateArray["property_id"] = 19;
$createDateArray["property_label"] = "Date Created";
$createDateArray["is_public"] = true;
//$createDateArray["@type"] = "http://www.w3.org/2001/XMLSchema#date";
$createDateArray["@value"] = $createDate;

$modifiedDateArray["type"] = "literal";//"numeric:timestamp";
$modifiedDateArray["property_id"] = 24;
$modifiedDateArray["property_label"] = "Date Modified";
$modifiedDateArray["is_public"] = true;
//$modifiedDateArray["@type"] = "http://www.w3.org/2001/XMLSchema#date";
$modifiedDateArray["@value"] = $modifiedDate;

$data["dcterms:created"] = $createDateArray;
$data["dcterms:modified"] = $modifiedDateArray;

$JSONdata = json_encode($data);

$fullURL = $url . $itemID . $authentication;
$headers = array('Content-Type: application/json'); 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fullURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONdata );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
curl_close($ch);
$responseArray = json_decode($response);
var_dump($responseArray);

echo $JSONdata;

So I added the brackets, (I’ll paste all my code for anyone who finds this later, and needs an easy copy)

<?php

$url = 'https://nfpl.historicniagara.ca/api/items/';
$authentication = '?key_identity=xxxxxxxx&key_credential=yyyyyyyyy';

$itemID = 89025;
$createDate = "2002-01-01 12:00:00";
$modifiedDate = "2005-01-20 11:23:41";

$createDateArray["type"] = "literal";//"numeric:timestamp";
$createDateArray["property_id"] = 19;
$createDateArray["property_label"] = "Date Created";
$createDateArray["is_public"] = true;
//$createDateArray["@type"] = "http://www.w3.org/2001/XMLSchema#date";
$createDateArray["@value"] = $createDate;

$modifiedDateArray["type"] = "literal";//"numeric:timestamp";
$modifiedDateArray["property_id"] = 24;
$modifiedDateArray["property_label"] = "Date Modified";
$modifiedDateArray["is_public"] = true;
//$modifiedDateArray["@type"] = "http://www.w3.org/2001/XMLSchema#date";
$modifiedDateArray["@value"] = $modifiedDate;

$data["dcterms:created"] = $createDateArray;
$data["dcterms:modified"] = $modifiedDateArray;

$JSONdata = "[".json_encode($data)."]";   // added brackets due to a difference between json_encode and what omeka api expects

$fullURL = $url . $itemID . $authentication;
$headers = array('Content-Type: application/json');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fullURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONdata );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
curl_close($ch);
$responseArray = json_decode($response);
var_dump($responseArray);

echo $JSONdata;

But it erased all the metadata… At least it didn’t delete the pictures attached, so I should be able to grab all the metadata, and “patch” it back with a copy of the complete data I want on the item. Better than doing the same with update, because at least the pictures don’t have to be re-ingested. I’ll update with the code I end up using later.

Yeah, that’s an unfortunate necessity of the patch/update process. It’s covered in the docs, though it could perhaps be worded better. Any patch that adds or changes value/s of a certain RDF property prefix (such as dcterms:) will end up replacing all of the values containing that same prefix, since they are treated as one big ‘key’ by the API update process.

The workaround, as you’ve found, is to export the existing data, make alterations, and use PATCH to update. This will update the values of the particular RDF flavor you choose, while still retaining any other metadata and attached media.

The way it reads to me in the docs, is that it treats each rdf properly separately, rather than an entire unit. So I expected that if I updated the subject field, it would overwrite all the subjects in the item.

Also, you’re saying that if it’s a different namespace like “bibo:” it won’t overwrite? Because that is not what I have found in my limited testing. “bibo:locator” was also overwritten.

You’re absolutely right, my apologies. I had the specifics wrong. Each RDF property is considered a key/unit, and the namespace has no bearing on what does and doesn’t get deleted–only the property & values currently being PATCHed.

No problem, just trying to troubleshoot and writing things down as we go. Your suggestion to add the square brackets was just the help I needed.

I just also want to leave a public record for the next person who has the same issues. My priorities right now are;

  1. Getting PATCH to add some fields to an existing item
  2. Making those fields available as timestamps. (for searching and formatting)
  3. Finding what is not throwing an error during api calls, and adding code so they do.
  4. Try to find how PATCH is working, and see if it can work the way it was intended. There’s a difference between what the documentation says should happen, and what actually happens.

The “PATCH” behavior treats any metadata property as being an update of “the properties” generally, as a whole. So when you specify metadata properties in a PATCH, they are replacing the full set of properties for that resource. If you provide no properties, the properties are maintained as they are. This is what the documentation is intended to mean when it mentions “removal of all other values.”

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.