Microsoft Outlook Download Attachment Error

Describe the issue/error/question

When trying to download an attachment from the Microsoft outlook node, i get the error “Id is malformed” when pulling the Id directly from the first node, however, if I copy the Id text and paste it directly, it works.

What is the error message (if any)?

Id is malformed

Share the output returned by the last node

{“message”:“Request failed with status code 400”,“name”:“Error”,“stack”:“Error: Request failed with status code 400\n at createError (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:269:11)\n at IncomingMessage.emit (events.js:327:22)\n at IncomingMessage.EventEmitter.emit (domain.js:467:12)\n at endReadableNT (internal/streams/readable.js:1327:12)\n at processTicksAndRejections (internal/process/task_queues.js:80:21)”}

Information on your n8n setup

n8n CLoud

Welcome to the community @KAL

You share three different workflows, so not sure which one I had to suppose to look at.

Probably you are referencing the getAll operation, which is returning some emails that do not have attachments. When you try to download an email that does not have an attachment, you get the error. To solve it, In the getAll operation, add the filter: hasAttachments eq true.

Hi, sorry, its the “Microsoft Outlook 2” , there is only 1 email in the box ,and it has attachments.

“Microsoft outlook” node gets a limit of 1 email, and returns:

[
  {
    "@odata.etag": "W/\"CQAAABYAAAAo2T0as3uTQo43vFtasDUHAAAAAAC/\"",
    "id": "AQMkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgBGAAADFFapDzNUM0ufZdFEJ-WgTQcAKNk9GrN7k0KON7xbWrA1BwAAAgEMAAAAKNk9GrN7k0KON7xbWrA1BwAAAgFnAAAA",
    "createdDateTime": "2022-01-14T19:43:09Z",
    "lastModifiedDateTime": "2022-01-14T19:43:10Z",
    "changeKey": "CQAAABYAAAAo2T0as3uTQo43vFtasDUHAAAAAAC/",
    "categories": [],
    "receivedDateTime": "2022-01-14T19:43:10Z",
    "sentDateTime": "2022-01-14T19:43:07Z",
    "hasAttachments": true,
    "internetMessageId": "<SY4P282MB11294291BD2E81B2843EDFA099549@SY4P282MB1129.AUSP282.PROD.OUTLOOK.COM>",
    "subject": "test",
    "bodyPreview": "ok\r\n\r\nSent from Mail for Windows",
    "importance": "normal",
    "parentFolderId": "AQMkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgAuAAADFFapDzNUM0ufZdFEJ-WgTQEAKNk9GrN7k0KON7xbWrA1BwAAAgEMAAAA",
    "conversationId": "AAQkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgAQAHLYAsHB0tFChet632smcN0=",
    "conversationIndex": "AQHYCX7kctgCwcHS0UKF63rfayZw3Q==",
    "isDeliveryReceiptRequested": false,
    "isReadReceiptRequested": false,
    "isRead": false,
    "isDraft": false,
    "webLink": "https://outlook.office365.com/owa/?ItemID=AQMkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgBGAAADFFapDzNUM0ufZdFEJ%2FWgTQcAKNk9GrN7k0KON7xbWrA1BwAAAgEMAAAAKNk9GrN7k0KON7xbWrA1BwAAAgFnAAAA&exvsurl=1&viewmodel=ReadMessageItem",
    "inferenceClassification": "focused",
    "body": {
      "contentType": "html",
      "content": "<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"Generator\" content=\"Microsoft Word 15 (filtered medium)\"><style>\r\n<!--\r\n@font-face\r\n\t{font-family:\"Cambria Math\"}\r\n@font-face\r\n\t{font-family:Calibri}\r\np.MsoNormal, li.MsoNormal, div.MsoNormal\r\n\t{margin:0cm;\r\n\tfont-size:11.0pt;\r\n\tfont-family:\"Calibri\",sans-serif}\r\na:link, span.MsoHyperlink\r\n\t{color:blue;\r\n\ttext-decoration:underline}\r\n.MsoChpDefault\r\n\t{}\r\n@page WordSection1\r\n\t{margin:72.0pt 72.0pt 72.0pt 72.0pt}\r\ndiv.WordSection1\r\n\t{}\r\n-->\r\n</style></head><body lang=\"EN-AU\" link=\"blue\" vlink=\"#954F72\" style=\"word-wrap:break-word\"><div class=\"WordSection1\"><p class=\"MsoNormal\">ok</p><p class=\"MsoNormal\">&nbsp;</p><p class=\"MsoNormal\">Sent from <a href=\"https://go.microsoft.com/fwlink/?LinkId=550986\">Mail</a> for Windows</p><p class=\"MsoNormal\">&nbsp;</p></div></body></html>"
    },
    "sender": {
      "emailAddress": {
        "name": "Chris | PCX",
        "address": "[email protected]"
      }
    },
    "from": {
      "emailAddress": {
        "name": "Chris | PCX",
        "address": "[email protected]"
      }
    },
    "toRecipients": [
      {
        "emailAddress": {
          "name": "KAL Jotforms",
          "address": "[email protected]"
        }
      }
    ],
    "ccRecipients": [],
    "bccRecipients": [],
    "replyTo": [],
    "flag": {
      "flagStatus": "notFlagged"
    }
  }
]

Outlook 1, gets the attachments

[
  {
    "@odata.etag": "W/\"CQAAABYAAAAo2T0as3uTQo43vFtasDUHAAAAAAC/\"",
    "id": "AQMkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgBGAAADFFapDzNUM0ufZdFEJ-WgTQcAKNk9GrN7k0KON7xbWrA1BwAAAgEMAAAAKNk9GrN7k0KON7xbWrA1BwAAAgFnAAAA",
    "createdDateTime": "2022-01-14T19:43:09Z",
    "lastModifiedDateTime": "2022-01-14T19:43:10Z",
    "changeKey": "CQAAABYAAAAo2T0as3uTQo43vFtasDUHAAAAAAC/",
    "categories": [],
    "receivedDateTime": "2022-01-14T19:43:10Z",
    "sentDateTime": "2022-01-14T19:43:07Z",
    "hasAttachments": true,
    "internetMessageId": "<SY4P282MB11294291BD2E81B2843EDFA099549@SY4P282MB1129.AUSP282.PROD.OUTLOOK.COM>",
    "subject": "test",
    "bodyPreview": "ok\r\n\r\nSent from Mail for Windows",
    "importance": "normal",
    "parentFolderId": "AQMkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgAuAAADFFapDzNUM0ufZdFEJ-WgTQEAKNk9GrN7k0KON7xbWrA1BwAAAgEMAAAA",
    "conversationId": "AAQkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgAQAHLYAsHB0tFChet632smcN0=",
    "conversationIndex": "AQHYCX7kctgCwcHS0UKF63rfayZw3Q==",
    "isDeliveryReceiptRequested": false,
    "isReadReceiptRequested": false,
    "isRead": false,
    "isDraft": false,
    "webLink": "https://outlook.office365.com/owa/?ItemID=AQMkAGY2NzJkNGFmLTgzNjUtNDVmNC1iYTQwLWEzN2QzYjYyMGU2ZgBGAAADFFapDzNUM0ufZdFEJ%2FWgTQcAKNk9GrN7k0KON7xbWrA1BwAAAgEMAAAAKNk9GrN7k0KON7xbWrA1BwAAAgFnAAAA&exvsurl=1&viewmodel=ReadMessageItem",
    "inferenceClassification": "focused",
    "body": {
      "contentType": "html",
      "content": "<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"Generator\" content=\"Microsoft Word 15 (filtered medium)\"><style>\r\n<!--\r\n@font-face\r\n\t{font-family:\"Cambria Math\"}\r\n@font-face\r\n\t{font-family:Calibri}\r\np.MsoNormal, li.MsoNormal, div.MsoNormal\r\n\t{margin:0cm;\r\n\tfont-size:11.0pt;\r\n\tfont-family:\"Calibri\",sans-serif}\r\na:link, span.MsoHyperlink\r\n\t{color:blue;\r\n\ttext-decoration:underline}\r\n.MsoChpDefault\r\n\t{}\r\n@page WordSection1\r\n\t{margin:72.0pt 72.0pt 72.0pt 72.0pt}\r\ndiv.WordSection1\r\n\t{}\r\n-->\r\n</style></head><body lang=\"EN-AU\" link=\"blue\" vlink=\"#954F72\" style=\"word-wrap:break-word\"><div class=\"WordSection1\"><p class=\"MsoNormal\">ok</p><p class=\"MsoNormal\">&nbsp;</p><p class=\"MsoNormal\">Sent from <a href=\"https://go.microsoft.com/fwlink/?LinkId=550986\">Mail</a> for Windows</p><p class=\"MsoNormal\">&nbsp;</p></div></body></html>"
    },
    "sender": {
      "emailAddress": {
        "name": "Chris | PCX",
        "address": "[email protected]"
      }
    },
    "from": {
      "emailAddress": {
        "name": "Chris | PCX",
        "address": "[email protected]"
      }
    },
    "toRecipients": [
      {
        "emailAddress": {
          "name": "KAL Jotforms",
          "address": "[email protected]"
        }
      }
    ],
    "ccRecipients": [],
    "bccRecipients": [],
    "replyTo": [],
    "flag": {
      "flagStatus": "notFlagged"
    }
  }
]

And outlook 2 is the problem.

When expression is


it returns
image

however, when manually pasting the same value in the Message Id field, it works fine


Can you please the whole workflow so I can replicate the issue?

{
  "name": "My workflow 2",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "limit": 1,
        "additionalFields": {}
      },
      "name": "Microsoft Outlook",
      "type": "n8n-nodes-base.microsoftOutlook",
      "typeVersion": 1,
      "position": [
        460,
        300
      ],
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "38",
          "name": "Microsoft Outlook account"
        }
      }
    },
    {
      "parameters": {
        "resource": "messageAttachment",
        "operation": "getAll",
        "messageId": "={{$json[\"id\"]}}",
        "additionalFields": {}
      },
      "name": "Microsoft Outlook1",
      "type": "n8n-nodes-base.microsoftOutlook",
      "typeVersion": 1,
      "position": [
        680,
        300
      ],
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "38",
          "name": "Microsoft Outlook account"
        }
      }
    },
    {
      "parameters": {
        "resource": "messageAttachment",
        "operation": "download",
        "messageId": "={{$node[\"Microsoft Outlook\"].json[\"id\"]}}",
        "attachmentId": "={{$json[\"id\"]}}"
      },
      "name": "Microsoft Outlook2",
      "type": "n8n-nodes-base.microsoftOutlook",
      "typeVersion": 1,
      "position": [
        900,
        300
      ],
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "38",
          "name": "Microsoft Outlook account"
        }
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Microsoft Outlook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Microsoft Outlook": {
      "main": [
        [
          {
            "node": "Microsoft Outlook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Microsoft Outlook1": {
      "main": [
        [
          {
            "node": "Microsoft Outlook2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 1040
}```

In the Outlook2 node, parameter Message ID set the expression to: {{$item(0).$node["Microsoft Outlook"].json["id"]}}

1 Like

Excellent, that worked, thank you so much.

Can you explain why or what i did wrong that caused it to fail so i don’t do it again?

Hi guys,

I’ve spent the past hour banging my head against a brick wall with this one… Is this a bug with the node? I’ve never seen the need to add $item(0) before a node value before.

Guessing it’s just outdated?

Hey @scottyb,

I suspect that is this the case the solution is over a year old. Can you open a new topic and fill out the template we can then take a look.