{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "49057997-4b97-4dc8-bdd1-a7596336c6ef",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        176,
        752
      ],
      "parameters": {
        "options": {
          "fileName": "=nominations_{{ $now.toString() }}.csv"
        },
        "binaryPropertyName": "nominations"
      },
      "typeVersion": 1.1
    },
    {
      "id": "c136156c-50fa-4778-86c6-1281ca22224d",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        400,
        400
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "d5498122-dfe5-414c-9a8a-b3d3f2407e22",
      "name": "Upload file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        384,
        944
      ],
      "parameters": {
        "name": "=nominations_{{$now.toString()}}.csv",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "0AMSgS_z8k1A-Uk9PVA",
          "cachedResultUrl": "https://drive.google.com/drive/folders/0AMSgS_z8k1A-Uk9PVA",
          "cachedResultName": "N8N drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1QaoP_--EGbSNMqFfe3WcUff7TugNj3En",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1QaoP_--EGbSNMqFfe3WcUff7TugNj3En",
          "cachedResultName": "App Store Featuring Submissions"
        },
        "authentication": "serviceAccount",
        "inputDataFieldName": "nominations"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "318d19eb-028e-4183-9f55-3c43ae67aeb4",
      "name": "Upload a file",
      "type": "n8n-nodes-base.slack",
      "position": [
        384,
        752
      ],
      "parameters": {
        "options": {
          "channelId": "=C09L0022N68",
          "initialComment": "={{ ['Hi! here\\'s the list of nominations :tada:', 'Hello!:smiling_face_with_3_hearts: list of nominations below, enjoy!  '][Math.floor(Math.random() * 2)] }}"
        },
        "resource": "file",
        "binaryPropertyName": "nominations"
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "0a6048c3-ded2-4ea9-8731-6222d1dbe759",
      "name": "Split Out1",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        400,
        144
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "977249ba-cdfa-41a7-bdfe-57f1e163a132",
      "name": "JWT Auth",
      "type": "n8n-nodes-base.jwt",
      "position": [
        -48,
        256
      ],
      "parameters": {
        "options": {
          "kid": "........"
        },
        "useJson": true,
        "claimsJson": "={\n  \"iss\": \"your_iss_here\",\n  \"aud\": \"appstoreconnect-v1\",\n  \"bid\": \"bundle_id_of_the_app\",\n  \"exp\": {{ Math.floor((new Date().getTime() + 10 * 60 * 1000) / 1000) }}\n}\n"
      },
      "credentials": {
        "jwtAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2e10c8a9-34e1-45ee-989d-c0421ca63f30",
      "name": "Fetch apps from App Store Connect",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        192,
        144
      ],
      "parameters": {
        "url": "https://api.appstoreconnect.apple.com/v1/apps",
        "options": {
          "pagination": {
            "pagination": {
              "nextURL": "={{$response.body.links[\"next\"]}}",
              "maxRequests": 3,
              "paginationMode": "responseContainsNextURL",
              "limitPagesFetched": true
            }
          }
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b05fbbc1-b995-4020-8c4d-3c1b680ba81f",
      "name": "Fetch submitted nominations from App Store Connect",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        192,
        400
      ],
      "parameters": {
        "url": "https://api.appstoreconnect.apple.com/v1/nominations",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "filter[state]",
              "value": "SUBMITTED"
            },
            {
              "name": "include",
              "value": "inAppEvents,relatedApps"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1121f3fd-fabc-4114-9d8a-16d5787cb721",
      "name": "Store applications in MySQL",
      "type": "n8n-nodes-base.mySql",
      "position": [
        608,
        144
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "applications",
          "cachedResultName": "applications"
        },
        "options": {},
        "dataMode": "defineBelow",
        "operation": "upsert",
        "valuesToSend": {
          "values": [
            {
              "value": "={{ $json.attributes.name }}",
              "column": "name"
            },
            {
              "value": "={{ $json.attributes.bundleId }}",
              "column": "bundle_id"
            }
          ]
        },
        "valueToMatchOn": "={{ $json.id.toNumber() }}",
        "columnToMatchOn": "apple_app_id"
      },
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.5
    },
    {
      "id": "959cc6ed-a27c-4880-9489-80d5889d8ea8",
      "name": "Store nominations in MySQL",
      "type": "n8n-nodes-base.mySql",
      "position": [
        608,
        400
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "nominations",
          "cachedResultName": "nominations"
        },
        "options": {},
        "dataMode": "defineBelow",
        "operation": "upsert",
        "valuesToSend": {
          "values": [
            {
              "value": "={{ $json.type }}",
              "column": "type"
            },
            {
              "value": "={{ $json.attributes.name }}",
              "column": "name"
            },
            {
              "value": "={{ $json.attributes.type }}",
              "column": "sub_type"
            },
            {
              "value": "={{ $json.attributes.description }}",
              "column": "description"
            },
            {
              "value": "={{  \n$if ($json.attributes.createdDate, DateTime.fromISO($json.attributes.createdDate, { zone: 'utc' }).toFormat('yyyy-MM-dd HH:mm:ss'), null)\n}}",
              "column": "created_at"
            },
            {
              "value": "={{  \n$if ($json.attributes.lastModifiedDate, DateTime.fromISO($json.attributes.lastModifiedDate, { zone: 'utc' }).toFormat('yyyy-MM-dd HH:mm:ss'), null)\n}}",
              "column": "last_modified_at"
            },
            {
              "value": "={{  \n$if ($json.attributes.submittedDate, DateTime.fromISO($json.attributes.submittedDate, { zone: 'utc' }).toFormat('yyyy-MM-dd HH:mm:ss'), null)\n}}",
              "column": "submitted_at"
            },
            {
              "value": "={{ $json.attributes.state }}",
              "column": "state"
            },
            {
              "value": "={{  \n$if ($json.attributes.publishStartDate, DateTime.fromISO($json.attributes.publishStartDate, { zone: 'utc' }).toFormat('yyyy-MM-dd HH:mm:ss'), null)\n}}",
              "column": "publish_start_at"
            },
            {
              "value": "={{  \n$if ($json.attributes.publishEndDate, DateTime.fromISO($json.attributes.publishEndDate, { zone: 'utc' }).toFormat('yyyy-MM-dd HH:mm:ss'), null)\n}}",
              "column": "publish_end_at"
            },
            {
              "value": "={{ $json.attributes.notes }}",
              "column": "notes"
            },
            {
              "value": "={{ $json.links.self }}",
              "column": "link"
            },
            {
              "value": "={{ $json.relationships.relatedApps.data[0].id.toNumber() }}",
              "column": "app_id"
            },
            {
              "value": "={{ $json.relationships.inAppEvents.data[0].id }}",
              "column": "in_app_event"
            }
          ]
        },
        "valueToMatchOn": "={{ $json.id }}",
        "columnToMatchOn": "nomination_id"
      },
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.5
    },
    {
      "id": "78b7631e-6cf4-4405-b7d7-ff357dc82945",
      "name": "Generate the report with a query",
      "type": "n8n-nodes-base.mySql",
      "position": [
        -32,
        752
      ],
      "parameters": {
        "query": "select  a.name as app_name,\n        n.name as nomination_name,\n        nomination_id, \n        app_id, \n        bundle_id, \n        sub_type, \n        submitted_at, \n        publish_start_at, \n        state   \nfrom app_store_featurings.nominations n \nleft join app_store_featurings.applications a on (n.app_id = a.apple_app_id)\norder by submitted_at desc",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.5
    },
    {
      "id": "9e830d1f-4394-4dee-b1e2-fdeffb5783ca",
      "name": "Weekly Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -320,
        400
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "daysInterval": 7,
              "triggerAtHour": 10
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "26cd9aaa-bc2d-4087-9b7a-eacb5689557c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        48
      ],
      "parameters": {
        "width": 384,
        "height": 224,
        "content": "CREATE TABLE `applications` (\n  `id` int NOT NULL AUTO_INCREMENT,\n  `apple_app_id` bigint NOT NULL,\n  `name` text NOT NULL,\n  `bundle_id` text NOT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `apple_app_id_UNIQUE` (`apple_app_id`)\n) ENGINE=InnoDB AUTO_INCREMENT=6378 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"
      },
      "typeVersion": 1
    },
    {
      "id": "dcf196f7-04a7-4261-9858-6a8d660648b4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        368
      ],
      "parameters": {
        "width": 400,
        "height": 464,
        "content": "CREATE TABLE `nominations` (\n  `id` int NOT NULL AUTO_INCREMENT,\n  `nomination_id` varchar(45) NOT NULL,\n  `app_id` bigint DEFAULT NULL,\n  `type` varchar(45) DEFAULT NULL,\n  `name` text,\n  `sub_type` varchar(45) DEFAULT NULL,\n  `description` text,\n  `created_at` datetime DEFAULT NULL,\n  `last_modified_at` datetime DEFAULT NULL,\n  `submitted_at` datetime DEFAULT NULL,\n  `state` varchar(45) DEFAULT NULL,\n  `publish_start_at` datetime DEFAULT NULL,\n  `publish_end_at` datetime DEFAULT NULL,\n  `notes` text,\n  `link` text,\n  `in_app_event` bigint DEFAULT NULL,\n  `store_account` varchar(45) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `nomination_id_UNIQUE` (`nomination_id`)\n) ENGINE=InnoDB AUTO_INCREMENT=911 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"
      },
      "typeVersion": 1
    },
    {
      "id": "ff176030-be3c-4352-b33f-03bb87c8256e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        112
      ],
      "parameters": {
        "width": 560,
        "height": 768,
        "content": "### Apple App Store Connect: Featuring Nominations Report\n\nThis workflow automates the process of tracking and reporting app nominations submitted to Apple for App Store featuring consideration. It connects to the App Store Connect API to fetch your list of apps and submitted nominations, stores the data in a MySQL database, and generates a report of all nominations. The report is then exported as a CSV file and can be automatically shared via Google Drive and Slack.\n\n#### Key features\n* Authenticates with App Store Connect using JWT.\n* Fetches all apps and submitted nominations, including details and related in-app events (API documentation: https://developer.apple.com/documentation/appstoreconnectapi/featuring-nominations)\n* Stores and updates app and nomination data in MySQL tables.\n* Generates a comprehensive nominations report with app and nomination details.\n* Exports the report as a CSV file.\n* Shares the report automatically to Google Drive and Slack.\n* Runs on a weekly schedule, but can be triggered manually as well.\n\n#### Setup Instructions\n* Obtain your App Store Connect API credentials (Issuer ID, Key ID, and private key) from your Apple Developer account.\n* Set up a MySQL database and configure the connection details in the workflow\u2019s MySQL node(s).\n* (Optional) Connect your Google Drive and Slack accounts using the respective n8n nodes if you want to share the report automatically.\n* Update any credentials in the workflow to match your setup.\n* Activate the workflow and set the schedule as needed.\n\n\nThis template is ideal for teams who regularly submit apps or updates for featuring on the App Store and want to keep track of their nomination history and status in a structured, automated way."
      },
      "typeVersion": 1
    },
    {
      "id": "d5476450-96d9-4267-ba5c-7e7ea6b87b8b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        96
      ],
      "parameters": {
        "width": 624,
        "height": 224,
        "content": "Fetch applications from App Store Connect API and store them in MySQL"
      },
      "typeVersion": 1
    },
    {
      "id": "52c173f4-e5f1-4408-877a-0ba02b8aeaf0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        352
      ],
      "parameters": {
        "width": 624,
        "height": 224,
        "content": "Fetch nominations from App Store Connect API and store them in MySQL"
      },
      "typeVersion": 1
    },
    {
      "id": "b788da30-b5f7-4fdb-8026-20c2552a3e30",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        176
      ],
      "parameters": {
        "width": 150,
        "height": 240,
        "content": "App Store Connect API authentication"
      },
      "typeVersion": 1
    },
    {
      "id": "61cb070d-7b27-45bf-ab92-81ee022052c1",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        704
      ],
      "parameters": {
        "width": 662,
        "height": 400,
        "content": "Run a SQL query to generate the report and upload it to Slack and Google Drive"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "JWT Auth": {
      "main": [
        [
          {
            "node": "Fetch submitted nominations from App Store Connect",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch apps from App Store Connect",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Store nominations in MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out1": {
      "main": [
        [
          {
            "node": "Store applications in MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Trigger": {
      "main": [
        [
          {
            "node": "JWT Auth",
            "type": "main",
            "index": 0
          },
          {
            "node": "Generate the report with a query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          },
          {
            "node": "Upload a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate the report with a query": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch apps from App Store Connect": {
      "main": [
        [
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch submitted nominations from App Store Connect": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}