{
  "nodes": [
    {
      "id": "aea55995-2c2c-4f59-8b68-43fa1871bb4c",
      "name": "Replace Images",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        860,
        140
      ],
      "parameters": {
        "url": "=https://slides.googleapis.com/v1/presentations/{{ $('Webhook').item.json[\"body\"][\"presentation_id\"] }}:batchUpdate ",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"requests\": [\n    {\n        \"replaceImage\": {\n          \"imageObjectId\": \"{{ $json.objectId }}\",\n          \"url\": \"{{ $('Webhook').item.json[\"body\"][\"image_url\"] }}\",\n          \"imageReplaceMethod\": \"CENTER_CROP\"\n        }\n    },\n    {\n      \"updatePageElementAltText\": {\n        \"objectId\": \"{{ $json.objectId }}\",\n        \"description\": \"{{ $('Webhook').item.json[\"body\"][\"image_key\"] }}\"\n      }\n    }\n  ]\n}  \n   ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleSlidesOAuth2Api"
      },
      "credentials": {
        "googleSlidesOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "92eeca3a-47b2-4daa-ac51-5b957c8d7d56",
      "name": "Error Missing Fields",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        500,
        340
      ],
      "parameters": {
        "options": {
          "responseCode": 500
        },
        "respondWith": "json",
        "responseBody": "{\n  \"error\": \"Missing fields.\"\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "14878542-6a42-4fe4-8dd6-328450a883eb",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1040,
        140
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "{\n  \"message\": \"Image replaced.\"\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "ac42249b-3c7d-4ba1-be7d-ba6e1ae652cd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        60,
        -540
      ],
      "parameters": {
        "width": 596.8395976509729,
        "height": 654.4370838798395,
        "content": "## \ub3d9\uc801\uc73c\ub85c Google Slides\uc5d0\uc11c \uc774\ubbf8\uc9c0\ub97c \uad50\uccb4\ud558\uae30\n\uc774 \uc6cc\ud06c\ud50c\ub85c\uc6b0\ub294 API \uc5d4\ub4dc\ud3ec\uc778\ud2b8\ub97c \ub178\ucd9c\ud558\uc5ec Google Slides\uc5d0\uc11c \uc774\ubbf8\uc9c0\ub97c \ub3d9\uc801\uc73c\ub85c \uad50\uccb4\ud560 \uc218 \uc788\uac8c \ud558\uba70, \ud504\ub808\uc820\ud14c\uc774\uc158 \ub371 \uc790\ub3d9\ud654\uc5d0 \uc801\ud569\ud569\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4 \ubc30\uacbd \uc5c5\ub370\uc774\ud2b8\ub098 \ud074\ub77c\uc774\uc5b8\ud2b8 \ub85c\uace0\uc640 \uac19\uc740 \uc791\uc5c5\uc5d0 \uc720\uc6a9\ud569\ub2c8\ub2e4.\n\n### 1\ub2e8\uacc4: Google Slides\uc5d0\uc11c \ud0a4 \uc2dd\ubcc4\uc790 \uc124\uc815\ud558\uae30\n\uad50\uccb4\ud560 \uc774\ubbf8\uc9c0\uc5d0 \uace0\uc720 \ud0a4 \uc2dd\ubcc4\uc790\ub97c \ucd94\uac00\ud569\ub2c8\ub2e4.\n1. \uc774\ubbf8\uc9c0\ub97c \ud074\ub9ad\ud569\ub2c8\ub2e4.\n2. **\ud615\uc2dd \uc635\uc158**\uc73c\ub85c \uc774\ub3d9\ud55c \ub2e4\uc74c **\ub300\uccb4 \ud14d\uc2a4\ud2b8**\ub97c \uc120\ud0dd\ud569\ub2c8\ub2e4.\n3. \uace0\uc720 \uc2dd\ubcc4\uc790(\uc608: `client_logo` \ub610\ub294 `background`)\ub97c \uc785\ub825\ud569\ub2c8\ub2e4.\n\n### 2\ub2e8\uacc4: POST \uc694\uccad\uc744 \uc0ac\uc6a9\ud558\uc5ec \uc774\ubbf8\uc9c0 \uc5c5\ub370\uc774\ud2b8\ud558\uae30\n\ub2e4\uc74c \ub9e4\uac1c\ubcc0\uc218\ub97c \ubcf8\ubb38\uc5d0 \ud3ec\ud568\ud558\uc5ec \uc6cc\ud06c\ud50c\ub85c\uc6b0 \uc5d4\ub4dc\ud3ec\uc778\ud2b8\uc5d0 POST \uc694\uccad\uc744 \ubcf4\ub0c5\ub2c8\ub2e4:\n- `presentation_id`: Google Slides \ud504\ub808\uc820\ud14c\uc774\uc158\uc758 ID\uc785\ub2c8\ub2e4. Google \ud504\ub808\uc820\ud14c\uc774\uc158 URL\uc5d0\uc11c \ucc3e\uc744 \uc218 \uc788\uc2b5\ub2c8\ub2e4: `https://docs.google.com/presentation/d/{\uc774 \ubd80\ubd84}/edit#slide=id.p`\n- `image_key`: \uc0dd\uc131\ud55c \uace0\uc720 \uc2dd\ubcc4\uc790\uc785\ub2c8\ub2e4.\n- `image_url`: \uc0c8 \uc774\ubbf8\uc9c0\uc758 URL\uc785\ub2c8\ub2e4.\n\n\uc774\uac8c \uc804\ubd80\uc785\ub2c8\ub2e4! Google Slides \ud504\ub808\uc820\ud14c\uc774\uc158\uc758 \uc9c0\uc815\ub41c \uc774\ubbf8\uc9c0\uac00 \uc81c\uacf5\ub41c URL\uc758 \uc0c8 \uc774\ubbf8\uc9c0\ub85c \uad50\uccb4\ub429\ub2c8\ub2e4.\n\n\uc774 \uc6cc\ud06c\ud50c\ub85c\uc6b0\ub294 \uc720\uc5f0\ud558\uac8c \uc124\uacc4\ub418\uc5b4 \uc5ec\ub7ec \uc2ac\ub77c\uc774\ub4dc\uc640 \ud504\ub808\uc820\ud14c\uc774\uc158\uc5d0\uc11c \ub3d9\uc77c\ud55c \uc2dd\ubcc4\uc790\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc2ac\ub77c\uc774\ub4dc \uc790\ub3d9\ud654 \ud504\ub85c\uc138\uc2a4\ub97c \uac04\uc18c\ud654\ud558\ub294 \ub370 \ub3c4\uc6c0\uc774 \ub418\uae30\ub97c \ubc14\ub78d\ub2c8\ub2e4!\n\n\uc990\uac81\uac8c \uc790\ub3d9\ud654\ud558\uc138\uc694!\nThe n8Ninja"
      },
      "typeVersion": 1
    },
    {
      "id": "735c5c4e-df8f-47ad-b0d7-ed57453a84d0",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        60,
        160
      ],
      "parameters": {
        "path": "replace-image-in-slide",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "22d1dd70-0716-4407-8e25-703355969e95",
      "name": "Retrieve matching Images ObjectIds",
      "type": "n8n-nodes-base.code",
      "position": [
        680,
        140
      ],
      "parameters": {
        "jsCode": "const key = $('Webhook').item.json.body.image_key;\n\nconst pageElements = $input\n  .all()\n  .flatMap(item => item.json.slides)\n  .flatMap(slide => slide.pageElements.filter(el => el.image && el.description === key));\n\nconst objectIds = pageElements.map(el => ({ objectId: el.objectId }));\n\nreturn objectIds"
      },
      "typeVersion": 2
    },
    {
      "id": "f942a8de-9fa8-4855-9be1-4247bae887e5",
      "name": "Retrieve All Slide Elements",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        500,
        140
      ],
      "parameters": {
        "url": "=https://slides.googleapis.com/v1/presentations/{{ $('Webhook').item.json.body.presentation_id }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleSlidesOAuth2Api"
      },
      "credentials": {
        "googleSlidesOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ddcbe7ed-9abc-49ac-98e5-4d5222a641d4",
      "name": "Check if all params are provided",
      "type": "n8n-nodes-base.if",
      "position": [
        260,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3272f7e8-4bc2-44bd-9760-437b2992e6e7",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.presentation_id }}",
              "rightValue": ""
            },
            {
              "id": "9e8abf56-622d-4704-95ea-c0f5f31683dd",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.image_key }}",
              "rightValue": ""
            },
            {
              "id": "d2cec4c9-2a90-4a24-ab6c-628689419698",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.image_url }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Check if all params are provided",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Replace Images": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve All Slide Elements": {
      "main": [
        [
          {
            "node": "Retrieve matching Images ObjectIds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if all params are provided": {
      "main": [
        [
          {
            "node": "Retrieve All Slide Elements",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Missing Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve matching Images ObjectIds": {
      "main": [
        [
          {
            "node": "Replace Images",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}