{
  "id": "ZYsZ7xetlnOXIk1i",
  "name": "Automatic export of Mirakl offers with email (CSV)",
  "tags": [],
  "nodes": [
    {
      "id": "63afe8f7-9ea7-49a4-9c14-d43bd7b3d0e8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 480,
        "height": 656,
        "content": "## Export automatique des offres Mirakl par email (CSV)\n\n### How it works\n\n1. The workflow is triggered on a schedule.\n2. Configuration variables like API URL and email are set.\n3. Offers are fetched from the Mirakl API.\n4. Fetched data is formatted into a spreadsheet.\n5. The formatted data is emailed using Gmail.\n\n### Setup steps\n\n- [ ] Configure the Schedule Trigger to define when the workflow runs.\n- [ ] Set the API URL, key, and email address in the configuration node.\n- [ ] Configure Gmail credentials for email sending.\n\n### Customization\n\nThe schedule for the workflow can be modified according to requirements. The destination email address can also be customized."
      },
      "typeVersion": 1
    },
    {
      "id": "f47caeb8-187d-41e3-ab6f-9feb56b60b89",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 272,
        "content": "## Initialize and configure workflow\n\nStarts the workflow and sets necessary configuration variables."
      },
      "typeVersion": 1
    },
    {
      "id": "193d3def-71b2-4822-a319-b4bfc6d6dcc7",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1344,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 304,
        "content": "## Fetch and transform data\n\nFetches offers from the Mirakl API and transforms the data into a tabular format."
      },
      "typeVersion": 1
    },
    {
      "id": "ba6362d6-298a-4090-b49e-d6c23ba86da5",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2048,
        0
      ],
      "parameters": {
        "color": 7,
        "height": 304,
        "content": "## Email formatted data\n\nSends the formatted data as an email using Gmail."
      },
      "typeVersion": 1
    },
    {
      "id": "74985c70-0d32-4d48-a55d-05d8d85c1650",
      "name": "Daily Export Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        608,
        128
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "04957e14-34e6-4f29-9407-e09b360e7e9e",
      "name": "Fetch Mirakl Offers",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1392,
        128
      ],
      "parameters": {
        "url": "={{ $json.api_url }}",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {}
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ $json.api_key }}"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "12186105-090e-4e8b-a0fe-0f4f529fcb89",
      "name": "Convert to Spreadsheet Format",
      "type": "n8n-nodes-base.code",
      "position": [
        1728,
        128
      ],
      "parameters": {
        "jsCode": "const csvContent = $json.data;\nconst fileName = `offres_mirakl_${new Date().toISOString().split('T')[0]}.csv`;\n\nreturn [\n  {\n    json: {},\n    binary: {\n      offres: await this.helpers.prepareBinaryData(\n        Buffer.from(csvContent, 'utf8'),\n        fileName,\n        'text/csv'\n      )\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "4ee4bb59-939d-4964-883a-ac7e6c6b30e6",
      "name": "Send Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2096,
        128
      ],
      "parameters": {
        "sendTo": "={{ $('Set Configuration Parameters').item.json.email }}",
        "message": "=Bonjour,\n\nVoici votre export automatique des offres Mirakl du jour.\n\nCordialement",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "offres"
              }
            ]
          }
        },
        "subject": "Rapport d'offres"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e55f154e-995c-4657-bbc2-2ec1180d1d83",
      "name": "Set Configuration Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "9a056f93-b2d3-4e94-ad2f-6642788a021c",
              "name": "api_url",
              "type": "string",
              "value": "https://votre-instance.mirakl.net/api/offers/export?include_inactive_offers=true"
            },
            {
              "id": "f9b0b645-0850-42d1-a5cb-8e192da5f6b5",
              "name": "api_key",
              "type": "string",
              "value": "ma_cle_api"
            },
            {
              "id": "2f7f0c3b-6e79-469f-8ced-06d5a4e5ecf4",
              "name": "email",
              "type": "string",
              "value": "mon_mail"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "5b3b3f36-5242-4114-806d-00e0cefd7e8b",
  "connections": {
    "Fetch Mirakl Offers": {
      "main": [
        [
          {
            "node": "Convert to Spreadsheet Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Export Trigger": {
      "main": [
        [
          {
            "node": "Set Configuration Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Configuration Parameters": {
      "main": [
        [
          {
            "node": "Fetch Mirakl Offers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to Spreadsheet Format": {
      "main": [
        [
          {
            "node": "Send Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}