Skip to main content
Hi all,





we'll upload usage data with a bulk api job to automate our process.





We transform our usage data in a python project but we are not able to create a cURL request in it to upload the data.





Did anyone of you tranfered the (BULK API) cURL request to python?





If yes I also can share our ideas.





Thanks,


Christian
Hi Christian,





Here's an example of a script converting the Bulk API cURL request to Python. It uses the 'requests' module and requests_toolbelt which is an extension of the requests module.





Original Bulk API cURL:





curl -v -X POST -H "Content-Type: multipart/form-data" -H "loginName: loginName" -H "appOrgId:xxxxOrgID" -H "accessKey:xxxxKey" --form "file=@/location/TestFile.csv" --form 'jobId=xxxx' -k https://url/v1.0/admin/connector/job/bulkimport





Python script:





###############





import requests


from requests_toolbelt.multipart.encoder import MultipartEncoder


multipart_data = MultipartEncoder(


    fields={


            'file': ('TestFile.csv', open('/location/TestFile.csv', 'rb'), 'text/csv'),


            'jobId': 'xxxx'


           }


    )


url = 'https://url/v1.0/admin/connector/job/bulkimport'


headers = {'content-type': multipart_data.content_type, 'loginName': 'loginName', 'appOrgId': 'xxxxOrgID', 'accessKey': 'xxxxKey'}


request = requests.post(url, data=multipart_data, headers=headers)


print request.text





Is this what you were looking for? 





Thanks,


Kunal
Thanks Kunal,





this is exactly what I'm looking for.





Thanks alot.


Best,





Christian
Great, glad to help! 

Reply