Can we validate CSV headers in Logic App ?

Ekta S. Date 1 Reputation point
2021-10-20T07:22:54.88+00:00

Require to validate Customer Email attachment which should contain CSV and CSV should have specific Columns only. Logic APP validate if attachment of email is CSV or not using 'Get item() ends with csv' formula. But could not find how to validate the structure of CSV i.e. column headers. Can you help ?

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,845 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 68,476 Reputation points
    2021-10-20T13:30:22.617+00:00

    @Ekta S. Date There is no out-of-box connector that can help you to validate the CSV headers but you can use different actions to get the CSV header.
    I am looping through the attachments and then verifying if the attachment name ends with the CSV or not last(split(items('For_each')?['name'],'.')).
    If it ends with the CSV name then I am reading the content of the csv file and getting the first rows that has the CSV header details.

    first(split(base64ToString(items('For_each')?['contentBytes']),'  
    '))  
    

    Code View : first(split(base64ToString(items('For_each')?['contentBytes']),'\n'))

    Workflow:
    142106-image.png

    CSV File passed as attachment:
    142098-image.png

    Variable has the value of headers:
    142125-image.png

    Now you can split the header value by comma and loop in to verify whether your required header is present or not. If you don't want to loop in actions then you can pass the header variable to inline code to perform your business logic (to check the required header) and pass the boolean value or as per your need.

    If you have complex logic then in case inline code didn't help then you can offload this functionality to the azure function.

    0 comments No comments