Uploading file data using cURL
If you want to upload data using the bulk API, you can use a cURL request to upload data from a .json or .csv file located on your machine. This differs from uploading data with JSON directly in the cURL request and is more suitable for larger amounts of data.
This tutorial will explain how to format your cURL request to upload data from a .json and .csv file on your machine. If you are not yet familiar with sending API requests using cURL, see the tutorial.
In this tutorial:
- Uploading data from a JSON file
- Uploading data from a CSV file
To upload data from a file:
Let's start by creating a contact import definition to be used to upload data.
POST /bulk/2.0/contacts/imports
{
"name": "Contact File Import",
"fields": {
"Email": "{{Contact.Field(C_EmailAddress)}}",
"FirstName": "{{Contact.Field(C_FirstName)}}"
},
"identifierFieldName": "Email",
"isSyncTriggeredOnImport": true
}
Here's the response.
{
"name": "Contact File Import",
"fields": {
"Email": "{{Contact.Field(C_EmailAddress)}}",
"FirstName": "{{Contact.Field(C_FirstName)}}"
},
"identifierFieldName": "Email",
"syncActions": [],
"isSyncTriggeredOnImport": true,
"dataRetentionDuration": "P7D",
"kbUsed": 0,
"isUpdatingMultipleMatchedRecords": false,
"uri": "/contacts/imports/30",
"createdBy": "API.User",
"createdAt": "2018-09-18T20:15:11.5900000Z",
"updatedBy": "API.User",
"updatedAt": "2018-09-18T20:15:11.5900000Z"
}
Let's walkthrough how to upload data to this definition from a file.
Uploading data from a .json file
You'll need a .json file on your machine. Our .json file is named "apitest.json" and it contains the following:
[
{
"Email": "john.doe@oracle.com",
"FirstName": "John"
},
{
"Email": "billy.bishop@oracle.com",
"FirstName": "Billy"
}
]
Using bash for our command line tool, navigate to the directory where your .json file is located.
cd C:\files
Next, we're going to send a POST request using cURL to upload data to the import definition we created with the id = 30.
curl --user "APITest\API.User" --header "Content-Type: application/json" --request POST --data "@apitest.json" https://secure.p03.eloqua.com/api/bulk/2.0/contacts/imports/30/data
Let's take a closer look at what's happening in the request as it differs from uploading data with JSON directly in the cURL request.
- The
--data
option is used with the file name of our .json file--data "@apitest.json"
- The
Content-Type
header is set toapplication/json
Because we set isSyncTriggeredOnImport
to true
for our import definition, the data was synced for us. The last step is to check the status of the sync.
Uploading data from a .csv file
You'll need a .csv file on your machine. Our .csv file is named "apitest.csv" and it contains the following:
Email,FirstName
john.doe@oracle.com,John
billy.bishop@oracle.com,Billy
Using bash for our command line tool, navigate to the directory where your .csv file is located.
cd C:\files
Next, upload data to the import definition we created earlier. Note that our .csv file is named "apitest.csv" and the Content-Type header is set to "text/csv".
curl --user "APITest\API.User" --header "Content-Type: text/csv" --request POST --data-binary "@apitest.csv" https://secure.p03.eloqua.com/api/bulk/2.0/contacts/imports/30/data
Let's take a closer look at what's happening in the request as it differs from uploading data with JSON directly in the curl request.
- The
--data-binary
option is used with the file name of our .csv file--data-binary "@apitest.csv"
- The
Content-Type
header is set totext/csv
Because we set isSyncTriggeredOnImport
to true
for our import definition, the data was synced for us. The last step is to check the status of the sync.