[Archivesspace_Users_Group] Trouble With API Endpoint ‘create a new job and post input files’

Bennett G Poulin bpoulin at unm.edu
Thu Oct 1 13:46:13 EDT 2020

(My apologies if this has been spammed to you. I have been having trouble with the listserv as I am new.)

Hello all,
We are new to the community and started playing around with the API in Python to help familiarize ourselves with it. I can connect and authenticate just fine, even call several of the endpoints without issue, but there is one that I cannot seem to figure out myself. The endpoint I’m trying to connect to is ‘create a new job and post input files’ and is documented here<http://archivesspace.github.io/archivesspace/api/#create-a-new-job-and-post-input-files>. I’m trying to use this endpoint to import EAD XML file(s) into a repository. I can use the create jobs<http://archivesspace.github.io/archivesspace/api/#create-a-new-job> endpoint without error, but there are no files, just filenames. I have tried looking through the previous threads here, but it is entirely possible that I missed something.
The Problem:
The problem that I am having is with the encoding for the file(s) that I send along with the post request. I’m bouncing between two errors ‘(RangeError) exceeded available parameter key space’ when I encode with Base64, and ‘(InvalidParameterError) invalid %-encoding’ when I do not. Base64 will bloat the data by 33%, but I’m only trying to send one file at the moment. Is there another encoding that’s preferred, or another way to get the files to the post request?
My Current Execution:
with open(os.path.join(repoDir, "filename.xml"), "r") as f1:
    f1_data = f1.read()
    f1_serialized = base64.b64encode(f1_data.encode())
jobs = json.dumps({
    "job": {
    "files": { #Omit files for jobs URI
        "filename.xml": f1_serialized.decode('utf-8')
createJobs = client.post('/repositories/4/jobs_with_files', jobs)

What I’ve tried:
I’ve tried changing the file open to “rb” and playing with the types of Base64 encoding methods.
I’ve tried adding the files as the third parameter as I’ve seen in other python API requests.
file = {"nmu-lmssking.xml": open(os.path.join(repoDir, "filename.xml"), "rb")}
createJobs = client.post('/repositories/4/jobs_with_files', json=jobs, files=file)

I have tried not encoding the file, but then I get the second error message mentioned above.
I have tried playing with the various file states of read, byte, and encoded data.

Other Relevant Information:
I’m using ArchivesSpace v2.7.1.
AS Documentation Image:
[cid:image001.png at 01D697E8.761A4BD0]
AS Documentation Text:
curl -H "X-ArchivesSpace-Session: $SESSION" \
  -d 'Example Missing' \
  "http://localhost:8089/repositories/2/jobs_with_files?job={"jsonmodel_type"=>"job", "status"=>"queued", "job"=>{"jsonmodel_type"=>"import_job", "filenames"=>["QJEOU", "PUDYO", "GD44820703", "UK255111B"], "import_type"=>"eac_xml"}}&files=UploadFile"

[:POST] /repositories/:repo_id/jobs_with_files
Create a new job and post input files
JSONModel(:job) job –
[RESTHelpers::UploadFile] files –
Integer repo_id – The Repository ID – The Repository must exist
200 – {:status => “Updated”, :id => (id of updated object)}

AS Ruby JSON Ruby Schema Files for Job and Import Job attached:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20201001/193639c3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 20823 bytes
Desc: image001.png
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20201001/193639c3/attachment.png>

More information about the Archivesspace_Users_Group mailing list