Setting media access level via API

We are using the Access module by @Daniel_KM to control access to some high-quality files that come with conditions on re-use. As there are several thousand items with media attached we are using the REST API to create the items and upload the files.

The Access module can either store the information about permissions and embargo dates in standard object properties, in which case they are editable in the main editing form, or it can use some special properties, editable from the Advanced tab when editing the media. We were hoping to use the latter option, which is the default. The media object would then look like this in the API. See the very bottom for the special fields:

{
  "@context": "http://omeka.local/api-context",
  "@id": "http://omeka.local/api/media/10976",
  "@type": "o:Media",
...
[snip]
...
  "o:filename": "27/BowmansLodge_1974_7_1_499.wrl",
  "o:lang": "",
  "o:original_url": "http://omeka.local/files/original/27/BowmansLodge_1974_7_1_499.wrl",
  "o:thumbnail_urls": [],
  "data": [],
  "o-access:status": {
    "level": "reserved",
    "level_set": "reserved"
  }
}

I had hoped we could update these fields when creating the media via POST or updating it via PUT, simply by adding the values to the JSON payload, but it seems to be ignored, and the access status always ends up with the level values set to “free”.

If it’s not possible to set it via the REST API then I suppose we will have to use ordinary properties, but if anyone (@Daniel_KM included) knows the secret of how to set the special values, I’d be interested to know!

Hi, I do not use this module, so please consider the following as a suggestion :wink:

According to the documentation of the access module, the access status is stored in a specific database table (probably named “access_status”, to be verified).

To have the REST API update this table, you could write a module that would attach a listener to the right API server event (see Server Event Reference - Omeka S Developer Documentation) and update the table accordingly.

Or you can more safely ask @Daniel_KM to include this option in a future release :slightly_smiling_face:

Also just speaking as an outsider, but it looks to me like the module here looks for incoming data in the JSON object under a top-level key access, so perhaps

{
    [rest of media json...]
    "access": {
        "o-access:level": "reserved"
    }
}

Thank you, @flatnes, that suggestion worked!

Excellent, thanks for the feedback and of course for the solution :clap: