API endpoint for posting locations to a space

Skip to first unread message

Max Eckard

Mar 1, 2017, 4:16:36 PM3/1/17
to Archivematica Tech
Hi all,

I don't think this is documented anywhere--are you able to post a location to a space through the API in the Storage Service? I've poked around here: https://github.com/artefactual/archivematica-storage-service/blob/stable/0.9.x/storage_service/locations/api/resources.py but it looks like you can only "browse," "post_detail," or "sword_collection", which all seem to rely on an already existing location.

If so, what might a request look like?


Max Eckard
Assistant Archivist for Digital Curation

Bentley Historical Library
1150 Beal Ave.
Ann Arbor, MI 48109-2113
(734) 763-7518

Holly Becker

Mar 1, 2017, 5:59:26 PM3/1/17
to Archivematica Tech
Hi Max,

I assume you're trying to create a Location via the storage service API.

The framework we're currently using (TastyPie) supports several endpoints by default to create/update/delete.  It looks like for both Locations & Spaces, we only allow fetching data via the API, not creating new locations [1], since only GET is allowed on the list.

If you allow POST by adding 'post' to list_allowed_methods, it would take the same format as a location returns from a GET.  Eg.

curl -v -X POST -H "Authorization:ApiKey test:95141fc645ed97a95893f1f865d24687f89a27ad" -H"content-type:application/json" -d'{"description":"Posted location", "purpose": "AS", "relative_path": "tmp", "space": "/api/v2/space/0353bd69-014e-4404-9728-3b4554a26cd0/", "pipeline": ["/api/v2/pipeline/31181a63-2d48-4c11-ab83-4d16aed88f9c/"]}' localhost:8000/api/v2/location/

However, that generates an error trying to associated the pipelines, so some additional work would have to be done to allow Locations to be created from the API.  We're looking at switching to Django REST Framework in the future, as it's better maintained than TastyPie, which would likely solve that particular issue.

Hope that helps,
Holly Becker
Lead Archivematica Developer

[1] https://github.com/artefactual/archivematica-storage-service/blob/stable/0.9.x/storage_service/locations/api/resources.py#L245-L246

Max Eckard

Mar 2, 2017, 9:52:32 AM3/2/17
to Holly Becker, Archivematica Tech
Thanks for the info, Holly!

What you've described in the curl example is exactly what I was hoping to do--too bad it results in an error!

Thanks again,

You received this message because you are subscribed to the Google Groups "Archivematica Tech" group.
To unsubscribe from this group and stop receiving emails from it, send an email to archivematica-tech+unsub...@googlegroups.com.
To post to this group, send email to archivematica-tech@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/archivematica-tech/57caef1b-5c40-4453-ad8c-17f133394bb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Holly Becker

Mar 2, 2017, 1:23:55 PM3/2/17
to Archivematica Tech
I looked at this a little more, and it looks like http://stackoverflow.com/questions/22601223/django-tastypie-imlementing-many-to-many-through-relationships describes the same error.  Locations and Pipelines are related through the cleverly-named LocationPipeline class.  These are analogous to the Sample, Region and SampleRegion respectively in the question.  If you want, you could look at implementing the modified save_m2m suggested in the answer.  It looks like the TastyPie function has changed a little since the questions was original answered though https://github.com/django-tastypie/django-tastypie/blob/v0.13.3/tastypie/resources.py#L2421-L2476

We'd be interested in a pull request with the changes if you do!

To post to this group, send email to archivema...@googlegroups.com.
Reply all
Reply to author
0 new messages