Hello everyone,
I’m trying to implement HTTP POST to import CSV data but always getting errors. i tried to follow similar subjects here but no success.
Here is the ERROR
{"status":"error","message":"Unable to process JSON","correlationId":"06cadc87-9dc7-4627-8c25-fe5029c27180"}
C# CODE
private readonly string filePath = @"..\net8.0\Data\hubspot_sample.csv";
private readonly string requestJsonPath = @"..\net8.0\Data\request.json";
public async Task UploadCSV()
{
var importRequest = System.IO.File.ReadAllText(requestJsonPath);
var formContent = new MultipartFormDataContent();
formContent.Add(
new StringContent(
importRequest,
System.Text.Encoding.UTF8,
"application/json"),
"importRequest");
// importFiles is a string[] of full file paths
formContent.Add(
new StreamContent(System.IO.File.OpenRead(filePath)),
"files",
Path.GetFileName(filePath));
var requestMessage = new HttpRequestMessage(
HttpMethod.Post,
"https://api.hubapi.com/crm/v3/imports"
)
{
Content = formContent
};
requestMessage.Headers.Add("Authorization", $"Bearer {API_KEY}");
requestMessage.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var response = await new HttpClient().SendAsync(requestMessage);
if (response.Content != null)
{
var jsonResponse = await response.Content.ReadAsStringAsync();
}
}
Request.json
// Example POST to https://api.hubspot.com/crm/v3/imports
// Content-Type header set to multipart/form-data
{
"name": "Association Label Import",
"dateFormat": "DAY_MONTH_YEAR",
"files": [
{
"fileName": "hubspot_sample.csv",
"fileFormat": "CSV",
"fileImportPage": {
"hasHeader": true,
"columnMappings": [
{
"columnObjectTypeId": "0-1",
"columnName": "Email",
"propertyName": "email"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Domain",
"propertyName": "domain"
}
//,
//{
// "columnName": "Association Label",
// "columnType": "FLEXIBLE_ASSOCIATION_LABEL",
// "columnObjectTypeId": "0-1",
// "toColumnObjectTypeId": "0-2"
//}
]
}
}
]
}
hubspot_sample.csv
Email,Domain
test2@test.com,www.test2.com,
Can anyone help what’s wrong ? Thanks