I am trying to post a csv file using the import API. I followed an example here, but still am getting an “unable to parse json format” error when making the request. Here is my code:
var key = ConfigurationManager.AppSettings["HSAPIKEY"];
var client = new RestClient(String.Format("https://api.hubapi.com/crm/v3/imports?hapikey={0}", key));
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "multipart/form-data");
request.AddHeader("Cookie", "__cfduid=d09cae7faeb5960760427f1cf3f5bfd7a1597311822");
string payload = @"{
""name"": ""test_import"",
""files"": [
{
""fileName"": ""hearing_first_test_2021-04-08.csv"",
""fileFormat"": ""CSV"",
""fileImportPage"": {
""hasHeader"": true,
""columnMappings"": [
{
""ignored"": false,
""columnName"": ""email_address"",
""idColumnType"": ""HUBSPOT_ALTERNATE_ID"",
""propertyName"": ""email"",
""foreignKeyType"": null,
""columnObjectTypeId"":""0-1"",
""associationIdentifierColumn"": false
},
{
""ignored"": false,
""columnName"": ""expected_due_date"",
""idColumnType"": ""null"",
""propertyName"": ""due_date"",
""foreignKeyType"": null,
""columnObjectTypeId"":""0-1"",
""associationIdentifierColumn"": false
},
{
""ignored"": false,
""columnName"": ""first_name"",
""idColumnType"": ""null"",
""propertyName"": ""firstname"",
""columnObjectTypeId"":""0-1"",
""associationIdentifierColumn"": false
},
{
""ignored"": false,
""columnName"": ""last_name"",
""idColumnType"": ""null"",
""propertyName"": ""lastname"",
""columnObjectTypeId"":""0-1"",
""associationIdentifierColumn"": false
},
{
""ignored"": false,
""columnName"": ""zipcode"",
""idColumnType"": ""null"",
""propertyName"": ""zip"",
""columnObjectTypeId"":""0-1"",
""associationIdentifierColumn"": false
},
{
""ignored"": false,
""columnName"": ""source_id"",
""idColumnType"": ""null"",
""propertyName"": ""bc_wte_contact"",
""columnObjectTypeId"":""0-1"",
""associationIdentifierColumn"": false
}
]
}
}
]
}";
request.AddParameter("importRequest", payload);
request.AddFile("files", AppDomain.CurrentDomain.BaseDirectory + "hearing_first_test_2021-04-08.csv");
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);
The error is:
“{\“status\”:\“error\”,\“message\”:\“Unable to process JSON\”,\“correlationId\”:\“d08507be-2b90-466e-99ec-1b6ab7fb76e9\”}”
The actual JSON generated that I’m posting is below and it validates in online JSON parsers.
{
"name": "test_import",
"files": [
{
"fileName": "hearing_first_test_2021-04-08.csv",
"fileFormat": "CSV",
"fileImportPage": {
"hasHeader": true,
"columnMappings": [
{
"ignored": false,
"columnName": "email_address",
"idColumnType": "HUBSPOT_ALTERNATE_ID",
"propertyName": "email",
"foreignKeyType": null,
"columnObjectTypeId":"0-1",
"associationIdentifierColumn": false
},
{
"ignored": false,
"columnName": "expected_due_date",
"idColumnType": "null",
"propertyName": "due_date",
"foreignKeyType": null,
"columnObjectTypeId":"0-1",
"associationIdentifierColumn": false
},
{
"ignored": false,
"columnName": "first_name",
"idColumnType": "null",
"propertyName": "firstname",
"columnObjectTypeId":"0-1",
"associationIdentifierColumn": false
},
{
"ignored": false,
"columnName": "last_name",
"idColumnType": "null",
"propertyName": "lastname",
"columnObjectTypeId":"0-1",
"associationIdentifierColumn": false
},
{
"ignored": false,
"columnName": "zipcode",
"idColumnType": "null",
"propertyName": "zip",
"columnObjectTypeId":"0-1",
"associationIdentifierColumn": false
},
{
"ignored": false,
"columnName": "source_id",
"idColumnType": "null",
"propertyName": "bc_wte_contact",
"columnObjectTypeId":"0-1",
"associationIdentifierColumn": false
}
]
}
}
]
}