Hi
I am still struggling a bit still with repeating items.
I am trying to get the company with every deal Hubspot and add it to a to a Postgres database. The problem is that I only get company for the first deal.
Kind regards
Mattias
Hi
I am still struggling a bit still with repeating items.
I am trying to get the company with every deal Hubspot and add it to a to a Postgres database. The problem is that I only get company for the first deal.
Kind regards
Mattias
@Mattias_Larsson The example below should do it.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"operation": "getAll",
"returnAll": true,
"filters": {
"includeAssociations": true
}
},
"name": "getDeals",
"type": "n8n-nodes-base.hubspot",
"typeVersion": 1,
"position": [
540,
300
],
"credentials": {
"hubspotApi": "asasas"
}
},
{
"parameters": {
"resource": "company",
"operation": "get",
"companyId": "={{$node[\"Function\"].json[\"associations\"][\"associatedCompanyIds\"][0]}}",
"additionalFields": {}
},
"name": "getCompanies",
"type": "n8n-nodes-base.hubspot",
"typeVersion": 1,
"position": [
990,
300
],
"credentials": {
"hubspotApi": "asasas"
}
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "id",
"value": "={{$item(0).$node[\"getCompanies\"].json[\"companyId\"]}}"
},
{
"name": "name",
"value": "={{$item(0).$node[\"getCompanies\"].json[\"properties\"][\"name\"][\"value\"]}}"
},
{
"name": "type",
"value": "="
},
{
"name": "status"
},
{
"name": "time_app_id"
}
],
"boolean": []
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
1250,
300
]
},
{
"parameters": {
"table": "crm_companies",
"columns": "id,name"
},
"name": "Postgres1",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
1490,
300
],
"credentials": {
"postgres": "asasasasasas"
}
},
{
"parameters": {
"functionCode": "const response = []\n\nfor (const item of items) {\n if (item.json.associations.associatedCompanyIds.length > 0) {\n response.push(item)\n }\n}\n\nreturn response;"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
760,
300
],
"notesInFlow": true,
"notes": "Clean"
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "getDeals",
"type": "main",
"index": 0
}
]
]
},
"getDeals": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"getCompanies": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Postgres1",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "getCompanies",
"type": "main",
"index": 0
}
]
]
}
}
}
Hi
Thanks for the answer. I still get the problem, only the company for the first deal get added for all.
ahh yes, I forget to edit the set node. Use the example below
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
390,
300
]
},
{
"parameters": {
"operation": "getAll",
"returnAll": true,
"filters": {
"includeAssociations": true
}
},
"name": "getDeals",
"type": "n8n-nodes-base.hubspot",
"typeVersion": 1,
"position": [
540,
300
],
"credentials": {
"hubspotApi": "asasas"
}
},
{
"parameters": {
"resource": "company",
"operation": "get",
"companyId": "={{$node[\"Function\"].json[\"associations\"][\"associatedCompanyIds\"][0]}}",
"additionalFields": {}
},
"name": "getCompanies",
"type": "n8n-nodes-base.hubspot",
"typeVersion": 1,
"position": [
990,
300
],
"credentials": {
"hubspotApi": "asasas"
}
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "id",
"value": "={{$node[\"getCompanies\"].json[\"companyId\"]}}"
},
{
"name": "name",
"value": "={{$node[\"getCompanies\"].json[\"properties\"][\"name\"][\"value\"]}}"
},
{
"name": "type",
"value": "="
},
{
"name": "status"
},
{
"name": "time_app_id"
}
],
"boolean": []
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
1250,
300
]
},
{
"parameters": {
"table": "crm_companies",
"columns": "id,name"
},
"name": "Postgres1",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
1490,
300
],
"credentials": {
"postgres": "asasasasasas"
}
},
{
"parameters": {
"functionCode": "const response = []\n\nfor (const item of items) {\n if (item.json.associations.associatedCompanyIds.length > 0) {\n response.push(item)\n }\n}\n\nreturn response;"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
760,
300
],
"notesInFlow": true,
"notes": "Clean"
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "getDeals",
"type": "main",
"index": 0
}
]
]
},
"getDeals": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"getCompanies": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Postgres1",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "getCompanies",
"type": "main",
"index": 0
}
]
]
}
}
}
Thanks, it works
I am trying to get this with mapping and repeating etc