{
  "schema_version": "1.0.0",
  "id": "email-attachment-to-drive",
  "title": "Save email attachments to Drive and log them",
  "category": "email",
  "difficulty": "beginner",
  "featured": false,
  "description": "Every attachment from matching emails is saved to a Drive folder, logged in a sheet with sender and date, and the email is labelled as filed.",
  "tags": [
    "email",
    "gmail",
    "google-drive",
    "attachments",
    "documents"
  ],
  "apps": [
    "Gmail",
    "Google Drive",
    "Google Sheets"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 3 steps after the trigger"
    ]
  },
  "tasks": {
    "typical": 3,
    "max": 3
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Attachment",
    "kind": "polling",
    "title": "New attachment on a document email",
    "why": "Fires once per attachment on emails matching the search, so an email with three PDFs gives three runs.",
    "config": {
      "Search String": "has:attachment -in:chats (to:docs@northwind-studio.example OR label:Documents)"
    },
    "outputs": [
      "message_id",
      "from_email",
      "from_name",
      "subject",
      "date",
      "attachment_name",
      "attachment_file"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "save",
      "kind": "action",
      "app": "Google Drive",
      "event": "Upload File",
      "title": "Save the file to Drive",
      "why": "Saves into one shared folder, with the date and sender in the name so files sort sensibly.",
      "fields": {
        "Drive": "Shared drive: Operations",
        "Folder": "Inbox documents",
        "File": "{{trigger.attachment_file}}",
        "File Name": "{{trigger.date}} {{trigger.from_name}} - {{trigger.attachment_name}}",
        "Convert To Document?": "No"
      },
      "outputs": [
        "id",
        "alternate_link"
      ]
    },
    {
      "key": "log",
      "kind": "action",
      "app": "Google Sheets",
      "event": "Create Spreadsheet Row",
      "title": "Log the file",
      "why": "A searchable index of what came in, from whom, and where it is.",
      "fields": {
        "Drive": "My Google Drive",
        "Spreadsheet": "Operations",
        "Worksheet": "Document log",
        "Columns": {
          "received_at": "{{trigger.date}}",
          "from": "{{trigger.from_email}}",
          "subject": "{{trigger.subject}}",
          "file_name": "{{trigger.attachment_name}}",
          "drive_link": "{{save.alternate_link}}"
        }
      },
      "outputs": [
        "id",
        "row_number"
      ]
    },
    {
      "key": "file",
      "kind": "action",
      "app": "Gmail",
      "event": "Add Label to Email",
      "title": "Label the email as filed",
      "why": "Tells everyone the attachment is already in Drive.",
      "fields": {
        "Message": "{{trigger.message_id}}",
        "Labels": "Documents/Filed"
      },
      "outputs": [
        "id"
      ]
    }
  ]
}
