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)0 -
You can also send the entire payload in JSON.I think I have shown this in my website
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.
0
Categories
- All Categories
- 124 Developer Announcements
- 54 Articles
- 156 General Questions
- 155 Thrust Services
- 56 Developer Hackathon
- 38 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9.1K Extended ECM
- 920 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 35 eDOCS
- 195 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 11 XM Fax
- Follow Categories