Still struggling with items

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

{
  "nodes": [
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": true,
        "filters": {}
      },
      "name": "getDeals",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        550,
        250
      ],
      "credentials": {
        "hubspotApi": "Maranics BPH"
      }
    },
    {
      "parameters": {
        "operation": "get",
        "dealId": "={{$item(0).$node[\"getDeals\"].json[\"dealId\"]}}",
        "additionalFields": {}
      },
      "name": "getDealDetails",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        750,
        250
      ],
      "credentials": {
        "hubspotApi": "Maranics BPH"
      }
    },
    {
      "parameters": {
        "resource": "company",
        "operation": "get",
        "companyId": "={{$item(0).$node[\"getDealDetails\"].json[\"associations\"][\"associatedCompanyIds\"][0]}}",
        "additionalFields": {}
      },
      "name": "getCompanies",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        1150,
        250
      ],
      "credentials": {
        "hubspotApi": "Maranics BPH"
      }
    },
    {
      "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": [
        1430,
        250
      ]
    },
    {
      "parameters": {
        "table": "crm_companies",
        "columns": "id,name"
      },
      "name": "Postgres1",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        1700,
        250
      ],
      "credentials": {
        "postgres": "Maranics postgres"
      }
    }
  ],
  "connections": {
    "getDeals": {
      "main": [
        [
          {
            "node": "getDealDetails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "getDealDetails": {
      "main": [
        [
          {
            "node": "getCompanies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "getCompanies": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Postgres1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@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