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
Page 1 / 1
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
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
this is exactly what I'm looking for.
Thanks alot.
Best,
Christian
Great, glad to help!
Reply
Sign up
If you ever had a profile with us, there's no need to create another one.
Don't worry if your email address has since changed, or you can't remember your login, just let us know at community@gainsight.com and we'll help you get started from where you left.
Else, please continue with the registration below.
Welcome to the Gainsight Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.