muledataweavemulesoftoutlook-restapi

Outlook 365 file attachment option auto-applies CSV column headers


I need to develop an integration using Mule which will create a *.csv file without headers, and email the file content as email attachment using Outlook 365.

Using DataWeave 2.0, I defined output application/csv header = false to create required CSV content without headers. Output of the DataWeave script is correct, which I checked in application logs and also by writing to local file system.

In the next step, I am passing this output payload to Outlook 365 using below code (MuleSoft Outlook 365 connector internally uses Outlook mail REST API - https://learn.microsoft.com/en-us/graph/api/resources/mail-api-overview?view=graph-rest-1.0):

%dw 2.0
import * from dw::core::Binaries
output application/json
---
{
    "message": {
        "subject": "Summary-" ++ now() as String {
            "format": "yyyyMMdd"
        },
        "body": {
            "contentType": "Text",
            "content": "Please find attached summary"
        },
        "toRecipients": [{
            "emailAddress": {
                "address": p('outlook.toRecipients')
            }
        }],
        "attachments": [{
            "@odata.type": "#microsoft.graph.fileAttachment",
            "name": "service-data.csv",
            "contentType": "application/csv",
            "contentBytes": toBase64(write(payload, "application/csv"))
        }]
    },
    "saveToSentItems": "true"
}

Receiver of this email finds column headers created in the attached file, example:

column_0,column_1,column_2,column_3,column_4,column_5,column_6,column_7,column_8,column_9,column_10,column_11,column_12,column_13,column_14,column_15,column_16,column_17,column_18
 ,SDEN1001107GR,Dense 7.3N 100mm,Days,0,,Blank,,,,,,,,,,,,

I debugged this, and looks like Outlook 365 connector automatically adds column header 'column_X' if not defined. But, the requirement is not to include headers in the file attachment.

Could anybody please help how to ignore the column headers in email attachment?

Sample request payload:

[
    {
        "Code": "SDEN1001107GR",
        "UnitUsagesUsage": "Days",
        "Group": "Blank",
        "Category": "A",
        "Description": "Dense 100mm",
        "Rate": "0"
    }
]

Solution

  • The issue seems to be that DataWeave -not the connector- is receiving the header=false property as a reader property rather than a writer property. For example in the read() function or in the outputMimeType attribute of a source or operation. Reader properties apply to the input of the script.

    You need to use as a writer property instead for the property to be applied to the output.

    In the write() function you add writer properties as an additional parameter:

    write(payload, "application/csv", {header: false})