{
  "name": "Pictory Text to Video",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [0, 0],
      "id": "88927e6a-4f96-4a29-b337-29ecce2c7d5e",
      "name": "When clicking 'Execute workflow'"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.pictory.ai/pictoryapis/v2/video/storyboard/render",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "YOUR_PICTORY_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "{     \"videoName\": \"demo_text_to_video\",     \"smartLayoutName\": \"Wanderlust\",     \"voiceOver\": {         \"enabled\": true,         \"aiVoices\": [             {                 \"speaker\": \"Brian\"             }         ]     },     \"backgroundMusic\": {         \"enabled\": true,         \"volume\": 0.1,         \"autoMusic\": true     },     \"scenes\": [         {             \"story\": \"AI is poised to significantly impact educators and course creators on social media. By automating tasks like content generation, visual design, and video editing, AI will save time and enhance consistency. This allows creators to focus on higher-level strategies and ensures a cohesive brand presence. AI can analyze social media interactions to tailor content to individual learner needs, making learning more engaging and effective. AI also offers advanced analytics, providing insights into content performance and audience engagement. Creators can quickly refine their strategies based on real-time data, ensuring their content remains relevant and impactful. Educators and course creators who adapt will likely expand their reach, improve content quality, and engage more effectively with their audiences on social media.\",             \"createSceneOnNewLine\": true,             \"createSceneOnEndOfSentence\": true         }     ] }",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [208, 0],
      "id": "edc81880-8d00-4293-8e00-27cfa037a040",
      "name": "Pictory Render Storyboard Video",
      "alwaysOutputData": true,
      "executeOnce": false
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "78c2c3e0-405f-4c34-ab8b-3ba26ea26df7",
              "name": "jobId",
              "value": "={{ $json.data.jobId }}",
              "type": "string"
            },
            {
              "id": "d0fb5913-5467-4da1-9177-b574668f573d",
              "name": "retryCount",
              "value": 0,
              "type": "number"
            },
            {
              "id": "b2832b72-7a37-4aba-8ced-e1aacea6e6c8",
              "name": "maxRetries",
              "value": 30,
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [416, 0],
      "id": "eb52c505-0868-4993-87c6-0689ba3bf46a",
      "name": "Set JobId",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "amount": 30
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [624, 0],
      "id": "dd8383e1-f2fd-4e0a-8e1d-8c4662deebc0",
      "name": "Wait for Job to Complete",
      "webhookId": "47dd6f5b-1f53-4515-9069-83bb3a05cdbf",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "url": "=https://api.pictory.ai/pictoryapis/v1/jobs/{{ $('Set JobId').item.json.jobId }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "YOUR_PICTORY_API_KEY"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [832, 0],
      "id": "792c0b5c-6e53-49a4-b5ed-48bd1632af1c",
      "name": "Get Job",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "962f322d-fb3e-4f76-8500-5684d03b6caf",
              "leftValue": "={{ $json.data.status }}",
              "rightValue": "completed",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "fc019aeb-88d9-452d-ab8b-391ae44629be",
              "leftValue": "={{ $json.data.status }}",
              "rightValue": "failed",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [1040, 0],
      "id": "a6474003-bc06-480e-8bf5-a2173415efcf",
      "name": "If Job is Completed or Failed",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e6ab6335-ea2d-4a11-b50a-16ccccf963e6",
              "name": "retryCount",
              "value": "={{ $('Set JobId').item.json.retryCount + 1}}",
              "type": "number"
            },
            {
              "id": "84e46426-780d-4643-aa5a-1b29437fe66b",
              "name": "jobId",
              "value": "={{ $('Set JobId').item.json.jobId }}",
              "type": "string"
            },
            {
              "id": "8f097c2f-b41b-4262-a58d-b0a1cc55109a",
              "name": "maxRetries",
              "value": "={{ $('Set JobId').item.json.maxRetries }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1200, 240],
      "id": "3ec5a426-873f-4469-91c3-3de1fda44827",
      "name": "Increment Retry",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "505028e7-663b-4b16-b4b4-28b719a0e682",
              "leftValue": "={{ $json.retryCount }}",
              "rightValue": "={{ $json.maxRetries }}",
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [1424, 240],
      "id": "c92403c8-844a-4475-bcad-21e3d281e387",
      "name": "Can Poll Job",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "a233a906-5dad-4419-913f-1bcbabb9ae6d",
              "leftValue": "={{ $json.data.status }}",
              "rightValue": "completed",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [1264, -128],
      "id": "be99384a-b4cd-4769-a404-9adaefe6fe4a",
      "name": "If Job Completed",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e9e4b25b-2390-4e8a-bfb7-f39c410a0c3f",
              "name": "videoUrl",
              "value": "={{ $json.data.videoURL }}",
              "type": "string"
            },
            {
              "id": "893f38b1-9df5-4cde-becb-42ae8d988c6a",
              "name": "videoShareUrl",
              "value": "={{ $json.data.videoShareURL }}",
              "type": "string"
            },
            {
              "id": "181757e6-1d7f-4141-b724-24a7d0bf504c",
              "name": "jobId",
              "value": "={{ $('Set JobId').item.json.jobId }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1472, -208],
      "id": "0c2a4f16-738b-474b-a91a-00843c4fcb01",
      "name": "Set Job Output",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2ebcb370-4594-49d1-96af-010949853f1e",
              "name": "status",
              "value": "failed",
              "type": "string"
            },
            {
              "id": "10943bab-4c1b-4921-9a13-5a1b56e4fcc6",
              "name": "reasonForFailure",
              "value": "job execution failed",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1472, -32],
      "id": "3c4c80de-fee5-4ecf-9a23-07785b66ad7b",
      "name": "Set Failed Job Status"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "39d40871-1527-415e-a0ff-1cd5a986a0b5",
              "name": "renderStatus",
              "value": "failed",
              "type": "string"
            },
            {
              "id": "e9b3522e-e4b2-4b9c-b00d-86d9af0b6734",
              "name": "reasonForFailure",
              "value": "job timed out",
              "type": "string"
            },
            {
              "id": "bbfda526-f361-4b72-b728-f6636f562a6b",
              "name": "jobId",
              "value": "={{ $('Set JobId').item.json.jobId }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1664, 256],
      "id": "5c010a32-8441-4338-8d27-498b7568e976",
      "name": "Set Timeout Job Status",
      "alwaysOutputData": true
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [
        [{ "node": "Pictory Render Storyboard Video", "type": "main", "index": 0 }]
      ]
    },
    "Pictory Render Storyboard Video": {
      "main": [
        [{ "node": "Set JobId", "type": "main", "index": 0 }]
      ]
    },
    "Set JobId": {
      "main": [
        [{ "node": "Wait for Job to Complete", "type": "main", "index": 0 }]
      ]
    },
    "Wait for Job to Complete": {
      "main": [
        [{ "node": "Get Job", "type": "main", "index": 0 }]
      ]
    },
    "Get Job": {
      "main": [
        [{ "node": "If Job is Completed or Failed", "type": "main", "index": 0 }]
      ]
    },
    "If Job is Completed or Failed": {
      "main": [
        [{ "node": "If Job Completed", "type": "main", "index": 0 }],
        [{ "node": "Increment Retry", "type": "main", "index": 0 }]
      ]
    },
    "Increment Retry": {
      "main": [
        [{ "node": "Can Poll Job", "type": "main", "index": 0 }]
      ]
    },
    "Can Poll Job": {
      "main": [
        [{ "node": "Wait for Job to Complete", "type": "main", "index": 0 }],
        [{ "node": "Set Timeout Job Status", "type": "main", "index": 0 }]
      ]
    },
    "If Job Completed": {
      "main": [
        [{ "node": "Set Job Output", "type": "main", "index": 0 }],
        [{ "node": "Set Failed Job Status", "type": "main", "index": 0 }]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  }
}
