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()
Refering to the beginning of this topic, we have two API endpoints for uploading files behaving differently:
### upload a new document ###
POST .../documents/upload/
### upload a new document file ###
POST .../documents/{document_id}/files/
In case of success, the first endpoint returns 200 OK state with the new document as JSON data as content.
While the second endpoint returns 202 Accepted state with an empty content body. Shouln’t it also return the JSON data of the created record (document file)? How can we else get the data of the created record?
I’m using the latest Mayan 4.5.7 version, as of now the included swagger documentation of the post document file endpoint seems to be out of date - parameters and returning values are different than documented.
Open source devs are a special breed of humans. I would not have had the patience to answer this politely after a user completely misses the point and then a tires to gaslight me.