Using the example in the docs to upload a file to a document returns a 400 error. The document was created successfully and as GET request to /api/v4/documents/{document_id} returns valid info about the document successfully.
Trying:
with open(file=‘filename.pdf’, mode=‘rb’) as file_object:
response = requests.post(url=‘http://127.0.0.1/api/v4/documents/25/files/’, auth=(‘XXX’,‘XXX’), files={‘file_new’: file_object}, data={‘action’: 1})
The reasons are quite clear. It was closed because it was not a bug.
Devs asked the forum for a decision that added a tons of features with the downside of one backward incompatible change. The community spoke and wanted the change.
I admire the patience the devs have with the community. Another reason to trust Mayan, very mature team.
Later another user stepped in providing more or less wrong input, also based on insufficient reading of changelogs. Which led to closing unfortunately the issue on the whole.
Thus the problem described by the original poster of this thread is comprehensible.
Thank you for pointing me in the right direction, got the /documents/{document_id}/files method call working… tried the /documents/upload/ method as it would be convenient, but apparently I’m missing something there also, the request looks like this:
with open(file=‘123.pdf’, mode=‘rb’) as file_object:
response = requests.post(url=‘http://127.0.0.1/api/v4/documents/upload/’, files={‘file_new’: file_object}, data={‘document_type’:{‘label’:‘Drawing’}})
and 404 response when adding a metadata item to a doc:
Please find the code snippets below from my working API integration. In my case I’m always using ids for foreign objects (Metadata Type or Document Type). I also noticed that my files-object for the first API call looks different. Do you also get a 404 response for the upload call?
def upload_document(self, document_type_id, label, file, description=None, filename=None, language=None):
url = f'......../documents/upload/'
files = { 'file': (f'{filename}', file )}
data = {
'document_type_id': document_type_id,
'description': description or '',
'label': label,
'language': language or 'Eng',
}
res = requests.post(url, auth=self.auth, verify=False, data=data, files=files)
return res.json()
and
def post_document_metadata(self, doc_id, metadata_type_id, value):
url = f'........../documents/{doc_id}/metadata/'
data = {
'metadata_type_id': metadata_type_id,
'value': value
}
res = requests.post(url, auth=self.auth, verify=False, data=data)
return res.json()