{
  "name": "SocialCrawl: Which of my accounts posted about a keyword",
  "nodes": [
    {
      "id": "node-1",
      "position": [
        260,
        0
      ],
      "name": "Run recipe",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "parameters": {}
    },
    {
      "id": "node-2",
      "position": [
        520,
        0
      ],
      "name": "setup 1: POST cohorts",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "method": "POST",
        "url": "https://www.socialcrawl.dev/v1/cohorts",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "{\n  \"name\": \"Q3 customers\"\n}",
        "options": {
          "timeout": 300000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $execution.id }}-setup-1"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "SocialCrawl API key"
        }
      },
      "executeOnce": true
    },
    {
      "id": "node-3",
      "position": [
        780,
        0
      ],
      "name": "setup 2: PUT cohorts/{cohortId}/members",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "method": "PUT",
        "url": "=https://www.socialcrawl.dev/v1/cohorts/{{ $('setup 1: POST cohorts').first().json.data.id }}/members",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "{\n  \"members\": [\n    {\n      \"platform\": \"tiktok\",\n      \"handle\": \"mrbeast\",\n      \"external_id\": \"cust_001\"\n    },\n    {\n      \"platform\": \"twitter\",\n      \"handle\": \"nasa\",\n      \"external_id\": \"cust_002\"\n    }\n  ]\n}",
        "options": {
          "timeout": 300000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $execution.id }}-setup-2"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "SocialCrawl API key"
        }
      },
      "executeOnce": true
    },
    {
      "id": "node-4",
      "position": [
        1040,
        0
      ],
      "name": "setup 3: POST cohorts/{cohortId}/queries",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "method": "POST",
        "url": "=https://www.socialcrawl.dev/v1/cohorts/{{ $('setup 1: POST cohorts').first().json.data.id }}/queries",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "{\n  \"keywords\": [\n    \"acme\"\n  ],\n  \"date_from\": \"2026-09-01T00:00:00.000Z\",\n  \"date_to\": \"2026-09-30T23:59:59.999Z\",\n  \"max_pages_per_identity\": 2,\n  \"max_items_per_identity\": 200,\n  \"max_credits\": 400\n}",
        "options": {
          "timeout": 300000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $execution.id }}-setup-3"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "SocialCrawl API key"
        }
      },
      "executeOnce": true
    },
    {
      "id": "node-5",
      "position": [
        1300,
        0
      ],
      "name": "setup 4: GET cohort-queries/{queryId}",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "method": "GET",
        "url": "=https://www.socialcrawl.dev/v1/cohort-queries/{{ $('setup 3: POST cohorts/{cohortId}/queries').first().json.data.query_id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 300000
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "SocialCrawl API key"
        }
      },
      "executeOnce": true,
      "retryOnFail": true,
      "maxTries": 4,
      "waitBetweenTries": 2000
    },
    {
      "id": "node-6",
      "position": [
        1560,
        0
      ],
      "name": "setup 4: GET cohort-queries/{queryId}: finished?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "setup 4: GET cohort-queries/{queryId}-finished",
              "leftValue": "={{ !['queued','running','pending'].includes($json.data.status) }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "node-7",
      "position": [
        1820,
        0
      ],
      "name": "setup 4: GET cohort-queries/{queryId}: wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "parameters": {
        "resume": "timeInterval",
        "amount": 5,
        "unit": "seconds"
      }
    },
    {
      "id": "node-8",
      "position": [
        2080,
        0
      ],
      "name": "setup 4: GET cohort-queries/{queryId}: result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "parameters": {
        "jsCode": "// The finished answer.\nreturn $input.all();"
      }
    },
    {
      "id": "node-9",
      "position": [
        2340,
        0
      ],
      "name": "setup 5: GET cohort-queries/{queryId}/results",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "method": "GET",
        "url": "=https://www.socialcrawl.dev/v1/cohort-queries/{{ $('setup 3: POST cohorts/{cohortId}/queries').first().json.data.query_id }}/results",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 300000
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "SocialCrawl API key"
        }
      },
      "executeOnce": true,
      "retryOnFail": true,
      "maxTries": 4,
      "waitBetweenTries": 2000
    },
    {
      "id": "note",
      "name": "How this recipe works",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -460
      ],
      "parameters": {
        "content": "## Which of my accounts posted about a keyword\n\nPrice for two hundred accounts, two pages each: a cohort query holds its full computed ceiling (estimated_credits), which depends on the members, platforms and page budget; see references/cohorts.md. Creating the cohort, uploading members, polling and reading results are free.\n\nMeasured on 25/10/2026: 4 credits in 24 calls for ITEMS=25. The TypeScript and Python programs both ran.\n\nFRESH=1 skips the cache and bills every call; a cache hit is free.\n\nInputs, set to a working example (change them to yours):\n\n  cohort_name: A label for the list\n\n  members: JSON array of {platform, handle, external_id}, up to a thousand per upload\n\n  keywords: JSON array of one to twenty keywords\n\n  date_from: Window start as a full RFC3339 timestamp\n\n  date_to: Window end as a full RFC3339 timestamp\n\n  max_pages: Page budget for each feed a member is read from, one to twenty; a feed with no next page reads one page whatever you set\n\n  max_credits: Safety limit: the query is rejected when its computed ceiling is above it\n\n**Key:** create a Header Auth credential named SocialCrawl API key, with Name x-api-key and your API key as Value, and pick it on every request node.\n\n**Rows:** a step that runs once per row takes the first 200 rows (change the number in its rows node).\n\n**Errors:** a request node stops the workflow on an API error. Read error.type in its output; retry only when error.retryable is true.",
        "width": 520,
        "height": 420
      }
    }
  ],
  "connections": {
    "Run recipe": {
      "main": [
        [
          {
            "node": "setup 1: POST cohorts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setup 1: POST cohorts": {
      "main": [
        [
          {
            "node": "setup 2: PUT cohorts/{cohortId}/members",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setup 2: PUT cohorts/{cohortId}/members": {
      "main": [
        [
          {
            "node": "setup 3: POST cohorts/{cohortId}/queries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setup 3: POST cohorts/{cohortId}/queries": {
      "main": [
        [
          {
            "node": "setup 4: GET cohort-queries/{queryId}",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setup 4: GET cohort-queries/{queryId}": {
      "main": [
        [
          {
            "node": "setup 4: GET cohort-queries/{queryId}: finished?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setup 4: GET cohort-queries/{queryId}: finished?": {
      "main": [
        [
          {
            "node": "setup 4: GET cohort-queries/{queryId}: result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "setup 4: GET cohort-queries/{queryId}: wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setup 4: GET cohort-queries/{queryId}: wait": {
      "main": [
        [
          {
            "node": "setup 4: GET cohort-queries/{queryId}",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setup 4: GET cohort-queries/{queryId}: result": {
      "main": [
        [
          {
            "node": "setup 5: GET cohort-queries/{queryId}/results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {}
}
