Add 2 files to a single document by api

Hi all,

Im addinfgfiles via API with :

response=requests.post(url=mayanapiaddress+‘/api/v4/documents/upload/’, files={‘file’: file_object},data={‘tag’:‘DocuwareArchiveDocument’, ‘document_type_id’: 7, ‘label’: F_SUBJECT}, headers=headers).json()

However some documents have more than 1 file , if i do

response=requests.post(url=mayanapiaddress+‘/api/v4/documents/upload/’, files={‘file’: file_object, ‘file’: file_object2},data={‘tag’:‘DocuwareArchiveDocument’, ‘document_type_id’: 7, ‘label’: F_SUBJECT}, headers=headers).json()

It creates 2 documents instead of 1 , How can I do this ?

I also tried using : response = requests.post(url=mayanapiaddress+“/api/v4/documents/” + str(documentid) + “/files/”, headers=headers, files={‘file_new’: file_object}, data={‘action’: 1})

and this returns error 400

thanks

1 Like

I’m unsure what is the issue you are experiencing.

However some documents have more than 1 file , if i do

You mean that you are uploading compressed files? And you want Mayan to create only a single document per upload even if you upload multiple files inside a .ZIP file?

I also tried using : response = requests.post(url=mayanapiaddress+“/api/v4/documents/” + str(documentid) + “/files/”, headers=headers, files={‘file_new’: file_object}, data={‘action’: 1})

and this returns error 400

This error is because the action parameter changed in version 4.5. It is now action_name. The values are:

  • append: Create a new version and append the new file pages.
  • keep: Do not create a new version and keep the current version pages.
  • replace: Create a new version and use the new file pages.

These values can be obtained via the API endpoint: api/v4/document_file_actions/

1 Like

Thank you , the problem here lies with my inexperince :slight_smile:

I solved it like this :

response = requests.post(url=mayanapiaddress+“/api/v4/documents/” + str(documentid) + “/files/”, headers=headers, files={‘file_new’: file_object2}, data={‘action_name’: ‘append’})

1 Like

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