create document issue using REST API in OTCS

Hi,

I'm trying to upload a file using following python code but I'm getting an error message, can you pls help me what I'm missing here

**************************************************

import requests
url = "https://xxxxxxxx.opentext.cloud/cs/cs/api/v2/nodes"
payload = 'type=144&parent_id=253389&name=testfile&file=C:/Test/Test.pdf'

headers = {  'Content-Type': 'application/x-www-form-urlencoded',  'Accept': 'application/json',  'OTCSTicket': '••••••'}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

*************************************
Error:
Response code : 500
"error": "An illegal attempt was made to upload a document"

Comments

  • I dont think so it will work with just giving the file path as you have done above:-

    import requests
    url = "https://<csname>/cs/cs/api/v1/nodes"
    payload = {'type': '144','name': 'download_folder','parent_id': '740928'}files=[  ('file',('1efd802d-40bc-44d0-9b2b-1530a8a46718',open('postman-cloud:///1efd802d-40bc-44d0-9b2b-1530a8a46718','rb'),'application/octet-stream'))]

    headers = {  'otcsticket': '2dc7757fc758fe420167741983d54dd94abd61f5fa2e6be76af8373906bcf52fec0892a6fc46967ac86069ae4a2f135446b2a7422036cd2154a7bf83e45fb348'}

    response = requests.request("POST", url, headers=headers, data=payload, files=files)
    print(response.text)


  • You can also send the entire payload in JSON.I think I have shown this in my website

    https://appukili.wordpress.com/2022/04/17/take-some-rest/

    OT only accepts the file as a part of multipart form data which you have done, but it expects hardcoded form parameters. If you take a postman successful payload and use its code generation wizard you should get what you need.I have an example in POJO as well.