{
  "name": "Community's solved questions",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -816,
        -32
      ],
      "id": "f6e5cc8b-7302-4fa2-bf76-58ab2f068e4f",
      "name": "When clicking \u2018Execute workflow\u2019"
    },
    {
      "parameters": {
        "url": "https://community.n8n.io/c/questions/12.json?solved=yes&order=created&ascending=true",
        "options": {
          "pagination": {
            "pagination": {
              "parameters": {
                "parameters": [
                  {
                    "name": "page",
                    "value": "={{ $pageCount }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ $response.body.topic_list.topics.length === 0 }}",
              "limitPagesFetched": true,
              "maxRequests": 30,
              "requestInterval": 1000
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -608,
        -32
      ],
      "id": "828db564-abcf-4a7a-92b7-be97ecd63201",
      "name": "Fetch Topics"
    },
    {
      "parameters": {
        "fieldToSplitOut": "topic_list.topics",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -400,
        -32
      ],
      "id": "055e234a-6fc8-49e9-891f-9e7af11c3026",
      "name": "Split Out"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c919804f-f505-4420-aee3-9ccc72edb9a6",
              "name": "Topic ID",
              "value": "={{ $json.topicId }}",
              "type": "number"
            },
            {
              "id": "f3515828-bb1f-47a4-96d5-0141df2856f3",
              "name": "Title",
              "value": "={{ $json.title }}",
              "type": "string"
            },
            {
              "id": "80959f43-aaec-4f39-a4b7-69c23d1ccc73",
              "name": "Question",
              "value": "={{ $json.questionText }}",
              "type": "string"
            },
            {
              "id": "0e81e7bf-d125-4df5-960a-43d7512f402c",
              "name": "Answer",
              "value": "={{ $json.answerText ?? ($json.cooked ?? '').replace(/<[^>]+>/g,'').substring(0,8000) }}",
              "type": "string"
            },
            {
              "id": "45c8b68b-0e9a-447f-acb4-da95aaef83db",
              "name": "Topic URL",
              "value": "={{ $json.topicUrl }}",
              "type": "string"
            },
            {
              "id": "d3f1fa63-f62c-4612-b7bd-3ae9b1ed2327",
              "name": "Views",
              "value": "={{ $json.views }}",
              "type": "number"
            },
            {
              "id": "a80e14d8-1201-48f3-b278-cb0e92f43f9a",
              "name": "Reply Count",
              "value": "={{ $json.replyCount }}",
              "type": "number"
            },
            {
              "id": "293ab701-0772-4fe4-8d33-93ab1f6ab170",
              "name": "Solved Date",
              "value": "={{ $json.createdAt }}",
              "type": "string"
            },
            {
              "id": "2197220b-08c5-4156-9a6e-aa83c1cf7ab7",
              "name": "Imported At",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        544,
        -32
      ],
      "id": "7a1fc4fe-1e5e-4c49-a7da-abe724556e9d",
      "name": "Build Final Airtable Record"
    },
    {
      "parameters": {
        "operation": "create",
        "base": {
          "__rl": true,
          "value": "YOUR_AIRTABLE_BASE_ID",
          "mode": "list",
          "cachedResultName": "Your Airtable Base",
          "cachedResultUrl": "https://airtable.com/YOUR_AIRTABLE_BASE_ID"
        },
        "table": {
          "__rl": true,
          "value": "YOUR_AIRTABLE_TABLE_ID",
          "mode": "list",
          "cachedResultName": "Your Table Name",
          "cachedResultUrl": "https://airtable.com/YOUR_AIRTABLE_BASE_ID/YOUR_AIRTABLE_TABLE_ID"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Views": "={{ $json.Views }}",
            "Reply Count": "={{ $json['Reply Count'] }}",
            "Topic ID": "={{ $json['Topic ID'] }}",
            "Title": "={{ $json.Title }}",
            "Question": "={{ $json.Question }}",
            "Answer": "={{ $json.Answer }}",
            "Topic URL": "={{ $json['Topic URL'] }}",
            "Imported At": "=={{ $now.toISODate() }}",
            "Solved Date": "={{ $DateTime.fromISO($json.solvedAt).toISODate() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Topic ID",
              "displayName": "Topic ID",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Title",
              "displayName": "Title",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Question",
              "displayName": "Question",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Answer",
              "displayName": "Answer",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Topic URL",
              "displayName": "Topic URL",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Views",
              "displayName": "Views",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Reply Count",
              "displayName": "Reply Count",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Solved Date",
              "displayName": "Solved Date",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "dateTime",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Imported At",
              "displayName": "Imported At",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "dateTime",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        784,
        -32
      ],
      "id": "9a7ca094-506b-4b17-b5c6-438c0596bb05",
      "name": "Create a record",
      "credentials": {
        "airtableTokenApi": {
          "id": "YOUR_CREDENTIAL_ID",
          "name": "Your Airtable Personal Access Token"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ 'https://community.n8n.io/t/' + $json.topicId + '.json' }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 1200
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        96,
        -32
      ],
      "id": "d28d6d0f-38ed-4fb9-ac1a-de7a5605f424",
      "name": "Fetch Topic Detail",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const detail = $input.item.json;\nconst posts = detail.post_stream?.posts ?? [];\n\nconst stripHtml = (html) => \n  (html ?? '').replace(/<[^>]+>/g, '').replace(/\\n{3,}/g, '\\n\\n').trim();\n\nconst questionText = stripHtml(posts[0]?.cooked).substring(0, 8000);\n\nconst answerPost = posts.find(p => p.accepted_answer === true);\nconst acceptedPostId = answerPost?.id ?? null;\nconst answerText = answerPost ? stripHtml(answerPost.cooked).substring(0, 8000) : null;\n\nreturn {\n  json: {\n    topicId:         $('Map Topic Fields').item.json.topicId,\n    title:           $('Map Topic Fields').item.json.title,\n    views:           $('Map Topic Fields').item.json.views,\n    replyCount:      $('Map Topic Fields').item.json.replyCount,\n    createdAt:       $('Map Topic Fields').item.json.createdAt,\n    topicUrl:        $('Map Topic Fields').item.json.topicUrl,\n    questionText,\n    answerText,\n    acceptedPostId,\n    solvedAt:        answerPost?.created_at ?? $('Map Topic Fields').item.json.createdAt,\n    needsAnswerFetch: answerText === null && acceptedPostId !== null\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        320,
        -32
      ],
      "id": "9a428a1c-0456-4699-a321-061f6c24b317",
      "name": "Extract Question & Answer"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9ee2405f-1ba2-4d00-b7ed-b60cdebf294e",
              "name": "topicId",
              "value": "={{ $json.id }}",
              "type": "number"
            },
            {
              "id": "268ef699-6132-45c9-be77-a0d35e01879c",
              "name": "title",
              "value": "={{ $json.title }}",
              "type": "string"
            },
            {
              "id": "37a73a1d-4744-4b7c-81d2-f8cedfbc1cd9",
              "name": "views",
              "value": "={{ $json.views ?? 0 }}",
              "type": "number"
            },
            {
              "id": "c9691ab2-0de3-4d53-8c63-cf568d619610",
              "name": "replyCount",
              "value": "={{ ($json.posts_count ?? 1) - 1 }}",
              "type": "number"
            },
            {
              "id": "bc8a060a-bf21-4adc-b9f0-81212aceb5b4",
              "name": "createdAt",
              "value": "={{ $json.created_at }}",
              "type": "string"
            },
            {
              "id": "2a7afbda-1976-48f8-a279-e26054649a77",
              "name": "topicUrl",
              "value": "={{ 'https://community.n8n.io/t/' + $json.slug + '/' + $json.id }}",
              "type": "string"
            },
            {
              "id": "2bfb19d8-74ec-4f1a-846d-4b3a7219c2d4",
              "name": "",
              "value": "",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -144,
        -32
      ],
      "id": "15d0aa11-43ed-4df3-b9d5-ffabb4276a99",
      "name": "Map Topic Fields"
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Fetch Topics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Topics": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Map Topic Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Final Airtable Record": {
      "main": [
        [
          {
            "node": "Create a record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Topic Detail": {
      "main": [
        [
          {
            "node": "Extract Question & Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Question & Answer": {
      "main": [
        [
          {
            "node": "Build Final Airtable Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map Topic Fields": {
      "main": [
        [
          {
            "node": "Fetch Topic Detail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "c9598f2a-2c30-4aba-b6d9-7d155bbc4293",
  "meta": {
    "instanceId": "YOUR_INSTANCE_ID"
  },
  "id": "",
  "tags": []
}
