0

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"
    }
]
5
  • Please share a sample of the first lines of the input payload to that DataWeave script. Commented Jan 24, 2023 at 17:11
  • I have attached the sample payload in above question Commented Jan 24, 2023 at 21:03
  • That payload is not a CSV. Does that mean that you didn't do the conversion in the previous step of the flow? Commented Jan 24, 2023 at 21:21
  • Please share the previous transformation and the output from that transformation that is the actual input to the script that you shared. The problem is likely there. Commented Jan 24, 2023 at 21:52
  • Also what is the source of the CSV file? Are you setting an outputMimeTyoe there? Commented Jan 25, 2023 at 1:47

1 Answer 1

0

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})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.