Hubspot / "crm/v3/imports/" / "source.on is not a function" / JSON issues

I’m using Hubspot crm/v3/imports API, sadly not part of Hubspot node so doing it manually.

All in all it’s not that complicated, you give it JSON with mapping and a csv file.

What is the error message (if any)?

I keep getting “source.on is not a function”. I did bunch of digging and error is given by n8n, call never goes to hubspot.
It seem like this error usually means JSON has some issues.
I’ve run out of ideas tbh, error doesn’t give any details what exactly is wrong but it seems it complains about the “importRequest” as swapping that into simple string sends the API to hubspot at least.

Please share your workflow

This is JSON as shown from “{{ $(‘importRequest’).item.json }}”

[Object: {"name": "salesExec - July", "importOperations": {"0-1": "UPSERT"}, "dateFormat": "DAY_MONTH_YEAR", "files": [{"fileName": "spreadsheet.csv", "fileFormat": "CSV", "fileImportPage": {"hasHeader": true, "columnMappings": [{"columnObjectTypeId": "0-1", "columnName": "firstname", "propertyName": "firstname"},{"columnObjectTypeId": "0-1", "columnName": "backyard_user_id", "propertyName": "backyard_user_id"},{"columnObjectTypeId": "0-1", "columnName": "company_number", "propertyName": "company_number"},{"columnObjectTypeId": "0-1", "columnName": "company", "propertyName": "company"},{"columnObjectTypeId": "0-1", "columnName": "hubspot_owner_id", "propertyName": "hubspot_owner_id"},{"columnObjectTypeId": "0-1", "columnName": "email", "propertyName": "email", "columnType": "HUBSPOT_ALTERNATE_ID"}]}}]}]

This is actually JSON I’ve made

[
  {
    "name": "salesExec - July",
    "importOperations": {
      "0-1": "UPSERT"
    },
    "dateFormat": "DAY_MONTH_YEAR",
    "files": [
      {
        "fileName": "spreadsheet.csv",
        "fileFormat": "CSV",
        "fileImportPage": {
          "hasHeader": true,
          "columnMappings": [
            {
              "columnObjectTypeId": "0-1",
              "columnName": "firstname",
              "propertyName": "firstname"
            },
            {
              "columnObjectTypeId": "0-1",
              "columnName": "backyard_user_id",
              "propertyName": "backyard_user_id"
            },
            {
              "columnObjectTypeId": "0-1",
              "columnName": "company_number",
              "propertyName": "company_number"
            },
            {
              "columnObjectTypeId": "0-1",
              "columnName": "company",
              "propertyName": "company"
            },
            {
              "columnObjectTypeId": "0-1",
              "columnName": "hubspot_owner_id",
              "propertyName": "hubspot_owner_id"
            },
            {
              "columnObjectTypeId": "0-1",
              "columnName": "email",
              "propertyName": "email",
              "columnType": "HUBSPOT_ALTERNATE_ID"
            }
          ]
        }
      }
    ]
  }
]

[email protected]

Hey @Mateusz_Bijakowski,

Have you tried setting the import request value to {{ JSON.stringify($(‘importRequest’).item.json) }} to see if that works?

{{ JSON.stringify($(‘importRequest’).item.json) }}

[ERROR: invalid syntax] when I copy from here, but when I type it in {{ JSON.stringify($('importRequest').item.json) }} it’s undefined.
Seems like weird formatting via markdown :man_shrugging:

Actually running it does something tho.
value becomes

{"name":"salesExec - July","importOperations":{"0-1":"UPSERT"},"dateFormat":"DAY_MONTH_YEAR","files":[{"fileName":"spreadsheet.csv","fileFormat":"CSV","fileImportPage":{"hasHeader":true,"columnMappings":[{"columnObjectTypeId":"0-1","columnName":"firstname","propertyName":"firstname"},{"columnObjectTypeId":"0-1","columnName":"backyard_user_id","propertyName":"backyard_user_id"},{"columnObjectTypeId":"0-1","columnName":"company_number","propertyName":"company_number"},{"columnObjectTypeId":"0-1","columnName":"company","propertyName":"company"},{"columnObjectTypeId":"0-1","columnName":"hubspot_owner_id","propertyName":"hubspot_owner_id"},{"columnObjectTypeId":"0-1","columnName":"email","propertyName":"email","columnType":"HUBSPOT_ALTERNATE_ID"}]}}]}

and it does get send to hubspot.
I feel like I’ve tried that already but maybe I didn’t run the node after it showed as undefiend.

Thank you for making me try again, I gues now I should see about that 500 I get from hubspot :joy:

Actually follow up.

Is this way to referencing n8n csv for API is correct? I struggled to find info about it.

Hey @Mateusz_Bijakowski,

Nice to hear it is partially working, When you say “referencing n8n csv for API” what do you mean? Assuming you mean is the expression in the files field correct I would say no, You should change the parameter type to n8n binary and for the value use the name of the binary item (normally data). If the binary data is not in the node before it you may want to use the merge node to bring that data closer to where you need it.

Ah, interesting.
It seems quite weird that I can’t use CSV from further up the chain easily.
In this case order of operations for last few nods wasn’t important so I just swapped them around.

It seems this solved my issue.

It looks like csv nodes and processing could use some work.
But I am positively surprised by rate of useful answers I’m getting here.

Wait,
is it also not possible to feed to CSV node content from non-previous node?

Hey @Mateusz_Bijakowski,

Not easily at the moment, This is one of those things that we know about but have not changed yet. Expect changes on this soon.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.