{
  "name": "Instagram Profile and Post Scraper",
  "nodes": [
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "GPT-4O"
        },
        "text": "=The following is an Instagram image. I've included a caption below as well.\n\nCaption: {{ $json.caption }}\n\nUse the image and the caption to write a customized one-line introduction. Use a no-frills tone of voice.\n\nExamples: \"I really liked your last pic—looks like you demolished that sandwich!\",\"Last pic looks like a lovely walk in the park.\"",
        "imageUrls": "={{ $json.imgUrl }}",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        1360,
        400
      ],
      "id": "55bb01f9-a326-4004-aec2-d672488d3229",
      "name": "OpenAI"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "32cb8a22-daae-4a7a-8728-d2e904a75f5e",
              "leftValue": "={{ $json.postUrl }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            },
            {
              "id": "4a2bf828-6b58-48ee-97cc-16bc971c8e68",
              "leftValue": "={{ $json.type }}",
              "rightValue": "Photo",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        1140,
        400
      ],
      "id": "b65bf7c5-9cc5-4e39-8d1a-f97f073fb169",
      "name": "Filter Posts Founded"
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Scraped Posts"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "profileUrl": "={{ $('Filter Posts Founded').item.json.profileUrl }}",
            "username": "={{ $('Filter Posts Founded').item.json.username }}",
            "fullName": "={{ $('Filter Posts Founded').item.json.fullName }}",
            "imgUrl": "={{ $('Filter Posts Founded').item.json.imgUrl }}",
            "query": "={{ $('Filter Posts Founded').item.json.query }}",
            "timestamp": "={{ $('Filter Posts Founded').item.json.timestamp }}",
            "postUrl": "={{ $('Filter Posts Founded').item.json.postUrl }}",
            "description": "={{ $('Filter Posts Founded').item.json.description }}",
            "commentCount": "={{ $('Filter Posts Founded').item.json.commentCount }}",
            "likeCount": "={{ $('Filter Posts Founded').item.json.likeCount }}",
            "location": "={{ $('Filter Posts Founded').item.json.location }}",
            "locationId": "={{ $('Filter Posts Founded').item.json.pubDate }}",
            "pubDate": "={{ $('Filter Posts Founded').item.json.pubDate }}",
            "likedByViewer": "={{ $('Filter Posts Founded').item.json.likedByViewer }}",
            "isSidecar": "={{ $('Filter Posts Founded').item.json.isSidecar }}",
            "type": "={{ $('Filter Posts Founded').item.json.type }}",
            "caption": "={{ $('Filter Posts Founded').item.json.caption }}",
            "postId": "={{ $('Filter Posts Founded').item.json.postId }}",
            "DM": "={{ $json.content }}"
          },
          "matchingColumns": [
            "postUrl"
          ],
          "schema": [
            {
              "id": "postUrl",
              "displayName": "postUrl",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "description",
              "displayName": "description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "commentCount",
              "displayName": "commentCount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "likeCount",
              "displayName": "likeCount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "location",
              "displayName": "location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "locationId",
              "displayName": "locationId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "pubDate",
              "displayName": "pubDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "likedByViewer",
              "displayName": "likedByViewer",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "isSidecar",
              "displayName": "isSidecar",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "type",
              "displayName": "type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "caption",
              "displayName": "caption",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "profileUrl",
              "displayName": "profileUrl",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "username",
              "displayName": "username",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "fullName",
              "displayName": "fullName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "imgUrl",
              "displayName": "imgUrl",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "postId",
              "displayName": "postId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "query",
              "displayName": "query",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "timestamp",
              "displayName": "timestamp",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "DM",
              "displayName": "DM",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1580,
        400
      ],
      "id": "b7e14a20-fa13-43b0-8abf-b11ad43e4d32",
      "name": "Add Posts"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        20,
        400
      ],
      "id": "8b0d9eff-7580-4226-a4e1-4c695c751586",
      "name": "Schedule Trigger1"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Authentication"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        240,
        400
      ],
      "id": "a22801f2-a952-46fc-b442-fb6bdcea0006",
      "name": "Get Authorization1"
    },
    {
      "parameters": {
        "amount": 1,
        "unit": "minutes"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        680,
        400
      ],
      "id": "3af4ffef-7dc5-4dad-9486-084ff91032f6",
      "name": "Wait 1min1",
      "webhookId": "8c670b00-2843-4880-b316-73d6a3f0ec96"
    },
    {
      "parameters": {
        "operation": "getOutput",
        "agentId": "YOUR_AGENT_ID",
        "additionalFields": {
          "prevContainerId": "={{ $('Launch Phantombuster1').item.json.containerId }}"
        }
      },
      "type": "n8n-nodes-base.phantombuster",
      "typeVersion": 1,
      "position": [
        900,
        400
      ],
      "id": "104aefd1-9f50-4e95-aa50-ed66388fcbdb",
      "name": "Get Phantombuster Output1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.phantombuster.com/api/v2/agents/launch",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "phantombusterApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {}
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"id\": \"YOUR_PHANTOMBUSTER_AGENT_ID\",\n    \"argument\": \"{\\\"csvName\\\":\\\"111\\\",\\\"sessionCookie\\\":\\\"{{ $json.sessionCookie }}\\\",\\\"spreadsheetUrl\\\":\\\"https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_FILE_ID/edit?gid=1458026136#gid=1458026136\\\",\\\"numberOfPostsPerProfile\\\":1}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        400
      ],
      "id": "4b7d0094-03c1-474b-92e3-f6e8662bf497",
      "name": "Launch Phantombuster1"
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "To Scrape"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "id": "={{ $json.id }}",
            "profileUrl": "={{ $json.profileUrl }}",
            "username": "={{ $json.username }}",
            "fullName": "={{ $json.fullName }}",
            "imgUrl": "={{ $json.imgUrl }}",
            "Private": "={{ $json.isPrivate }}",
            "isVerified": "={{ $json.isVerified }}",
            "query": "={{ $json.query }}",
            "timestamp": "={{ $json.timestamp }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "profileUrl",
              "displayName": "profileUrl",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "username",
              "displayName": "username",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "fullName",
              "displayName": "fullName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "imgUrl",
              "displayName": "imgUrl",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Private",
              "displayName": "Private",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "isVerified",
              "displayName": "isVerified",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "query",
              "displayName": "query",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "timestamp",
              "displayName": "timestamp",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1340,
        0
      ],
      "id": "fea8c6c0-cbaa-4a46-878f-71614e9f7765",
      "name": "Add profiles1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.phantombuster.com/api/v2/agents/launch",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "phantombusterApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {}
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"id\": \"YOUR_PHANTOMBUSTER_AGENT_ID\",\n    \"argument\": \"{\\\"sessionCookie\\\":\\\"{{ $json.sessionCookie }}\\\",\\\"spreadsheetUrl\\\":\\\"https://www.instagram.com/example_creator/\\\",\\\"numberMaxOfFollowers\\\":100,\\\"numberofProfilesperLaunch\\\":100}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        0
      ],
      "id": "c1cb8d2f-46dc-438c-8efd-42e6165b74eb",
      "name": "Launch Phantombuster2"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Authentication"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        240,
        0
      ],
      "id": "f6a5c10f-601b-4e73-8dae-0ad10fbaf663",
      "name": "Get Authorization2"
    },
    {
      "parameters": {
        "amount": 1,
        "unit": "minutes"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        680,
        0
      ],
      "id": "4706a5e3-32bf-4d8f-b677-6e8bdc7d9764",
      "name": "Wait 1min2",
      "webhookId": "83a105c4-6352-4edc-a49e-85047b466de9"
    },
    {
      "parameters": {
        "operation": "getOutput",
        "agentId": "YOUR_AGENT_ID",
        "additionalFields": {
          "prevContainerId": "={{ $('Launch Phantombuster2').item.json.containerId }}"
        }
      },
      "type": "n8n-nodes-base.phantombuster",
      "typeVersion": 1,
      "position": [
        900,
        0
      ],
      "id": "9a93324c-a9b9-4015-b2fe-8f628616be23",
      "name": "Get Phantombuster Output2"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "4f8584a3-6e3f-415a-9133-57a1dacfe7ff",
              "leftValue": "={{ $json.profileUrl }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        1120,
        0
      ],
      "id": "7c8e0143-cfe5-4c8f-bb7d-465a91a824a0",
      "name": "Filter1"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        20,
        0
      ],
      "id": "a6f813fe-15d9-4cfb-b41a-47c655c904be",
      "name": "Schedule Trigger2"
    }
  ],
  "connections": {
    "OpenAI": {
      "main": [
        [
          {
            "node": "Add Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Posts Founded": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "Get Authorization1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Authorization1": {
      "main": [
        [
          {
            "node": "Launch Phantombuster1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1min1": {
      "main": [
        [
          {
            "node": "Get Phantombuster Output1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Phantombuster Output1": {
      "main": [
        [
          {
            "node": "Filter Posts Founded",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Launch Phantombuster1": {
      "main": [
        [
          {
            "node": "Wait 1min1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Launch Phantombuster2": {
      "main": [
        [
          {
            "node": "Wait 1min2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Authorization2": {
      "main": [
        [
          {
            "node": "Launch Phantombuster2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1min2": {
      "main": [
        [
          {
            "node": "Get Phantombuster Output2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Phantombuster Output2": {
      "main": [
        [
          {
            "node": "Filter1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter1": {
      "main": [
        [
          {
            "node": "Add profiles1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger2": {
      "main": [
        [
          {
            "node": "Get Authorization2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
