I am working on settign up a company & contacts import from file using powershell but am running into a problem properly formatting the request and getting it to import both files.
I get this error:
Exception: Cannot bind parameter ‘Form’. Cannot convert the “[the form JSON is here]” value of type “System.String” to type “System.Collections.IDictionary”.
Here is my code:
Clear-Host
$hubSpotheaders = @{
Authorization = "Bearer pat-xxxxxxxxxxxxxxx"
}
$path = "C:\pathtofile"
$companyupdatefile = "$path\Paragon Companies_20241105.xlsx"
$contactfile = "$path\Paragon Contacts_20241105.xlsx"
$post = 'importRequest={
"name": "isolved Paragon 20241105",
"dateFormat": "MONTH_DAY_YEAR",
"createContactListFromImport": true,
"marketableContactImport": false,
"files": [
{
"fileName": "Paragon Contacts_20241105.xlsx",
"fileFormat": "SPREADSHEET",
"fileImportPage": {
"hasHeader": true,
"columnMappings": [
{
"columnObjectTypeId": "0-1",
"columnName": "Company Name",
"propertyName": "company"
},
{
"columnObjectTypeId": "0-1",
"columnName": "Client ID",
"propertyName": "client_id",
"associationIdentifierColumn": true
},
{
"columnObjectTypeId": "0-1",
"columnName": "Phone Number",
"propertyName": "phone"
},
{
"columnObjectTypeId": "0-1",
"columnName": "Email",
"propertyName": "email"
},
{
"columnObjectTypeId": "0-1",
"columnName": "Job Title",
"propertyName": "jobtitle"
},
{
"columnObjectTypeId": "0-1",
"columnName": "Type of Contact",
"propertyName": "type_of_contact"
},
{
"columnObjectTypeId": "0-1",
"columnName": "Last Name",
"propertyName": "lastname"
},
{
"columnObjectTypeId": "0-1",
"columnName": "First Name",
"propertyName": "firstname"
},
{
"columnObjectTypeId": "0-1",
"columnName": "Type",
"propertyName": "type"
}
]
}
},
{
"fileName": "Paragon Companies_20241105.xlsx",
"fileFormat": "SPREADSHEET",
"fileImportPage": {
"hasHeader": true,
"columnMappings": [
{
"columnObjectTypeId": "0-2",
"toColumnObjectTypeId": "0-1",
"columnName": "Client ID",
"propertyName": null,
"foreignKeyType": {
"associationTypeId": 280,
"associationCategory": "HUBSPOT_DEFINED"
}
},
{
"columnObjectTypeId": "0-2",
"columnName": "Company Name",
"propertyName": "name"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Legal\Company ID",
"propertyName": "company_id"
},
{
"columnObjectTypeId": "0-2",
"columnName": "DBA",
"propertyName": "dba"
},
{
"columnObjectTypeId": "0-2",
"columnName": "EIN",
"propertyName": "ein"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Account Status",
"propertyName": "account_status"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Record ID",
"propertyName": "hs_object_id",
"columnType": "HUBSPOT_OBJECT_ID"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Active Employee Count",
"propertyName": "active_employee_count"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Payroll System",
"propertyName": "payroll_system"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Type",
"propertyName": "type"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Company Legal State",
"propertyName": "client_legal_state"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Legal Address",
"propertyName": "legal_address"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Service List",
"propertyName": "service_list"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Payroll Frequency",
"propertyName": "frequency"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Parent Company",
"propertyName": "hs_parent_company_id"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Termination Tax Effective Date",
"propertyName": "termination_tax_effective_date"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Termination Date Notified",
"propertyName": "termination_date_notified"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Termination Process Quarterlies Thru",
"propertyName": "termination_process_quarterlies_thru"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Termination Process Zero Filings Thru",
"propertyName": "termination_process_zero_filings_thru"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Termination Annual\Process W2",
"propertyName": "termination_annual_process_w2"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Termination Final Tax Return Date",
"propertyName": "termination_final_tax_return_date"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Termination Reason",
"propertyName": "termination_reason"
},
{
"columnObjectTypeId": "0-2",
"columnName": "Term Date",
"propertyName": "term_date"
}
]
}
}
]
}'
$URL = "https://api.hubapi.com/crm/v3/imports"
try {
Invoke-RestMethod -Uri $URL -Headers $hubSpotheaders -Method Post -ContentType "multipart/form-data" -form $post
} catch {
write-host "Error:" $_.ErrorDetails.Message
write-host "Exception:" $_.Exception.Message
}