Logic App workflow that retrieves JSON data from an HTTP request and converts it into a CSV format

Creating a Logic App workflow to convert an HTTP JSON request into a CSV table involves several steps. Below is a step-by-step guide with a detailed explanation and example.

Scenario

  1. You receive an HTTP POST request with JSON data.
  2. You parse the JSON data.
  3. You convert the JSON data into a CSV table.
  4. You send it as an email attachment.

Step-by-Step Workflow

Step 1: Create a Logic App

  1. Go to the Azure portal.
  2. Click on Create a resource > Integration > Logic App.
  3. Provide a name, subscription, resource group, and location for your Logic App.
  4. Click Review + create and then Create.

Step 2: Add an HTTP Trigger

  1. Open your Logic App in the designer.
  2. Search for the HTTP Request trigger and add it.
  3. Save the Logic App. This will generate a URL for the HTTP endpoint.
  4. Copy the URL for testing later.

Step 3: Parse JSON Data

  1. Add a new action after the HTTP trigger.
  2. Search for Parse JSON and add it.
  3. In the Content field, select the Body from the HTTP trigger.
  4. Provide a JSON schema for the incoming data. For example:
     
    {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "name": { "type": "string" },
          "email": { "type": "string" }
        }
      }
    }

    This schema assumes the incoming JSON is an array of objects with idname, and email fields.

Step 4: Create a CSV Table

  1. Add a new action after the Parse JSON action.
  2. Search for Create CSV table and add it.
  3. In the From field, select the output of the Parse JSON action.
  4. Specify the columns for the CSV table. For example:
    • Column 1: Id
    • Column 2: Name
    • Column 3: Email

Step 5:  Send the CSV File

  1. Add a new action after the Create CSV table action.
  2. Search for Gmail (or your email provider) and select Send email (V2).
  3. Connect to your email account.
  4. Fill in the email details (To, Subject, Body).
  5. In the Attachments section:
    • Add the Create CSV table output as the attachment content.
    • Specify a file name (e.g., data.csv).
Here's how Logic App should look:
estudy247-la-test-csvtable-10

Example Workflow

  1. HTTP Request Trigger:
    • Method: POST
    • URL: (Generated URL)
  2. Parse JSON Action:
    • Content: Body from the HTTP trigger
    • Schema:
      {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": { "type": "integer" },
            "name": { "type": "string" },
            "email": { "type": "string" }
          }
        }
      }
  3. Create CSV Table Action:
    • From: Output of Parse JSON
    • Columns: Id, Name, Email
  4. Create  Send Email Action:
    • Email content: Output of Create CSV table
    • File name: data.csv

Testing the Workflow

Use a tool like Postman to send a POST request to the HTTP trigger URL with the following JSON payload:

[
  { "id": 101, "name": "Priya Singh", "email": "priya@example.com" },
  { "id": 102, "name": "Jane Smith", "email": "jane@example.com" }
]

Sample CSV Output

The resulting CSV file will look like this:

Id,Name,Email
101,Priya Singh,priya@example.com
102,Jane Smith,jane@example.com
This workflow is highly customizable and can be adapted to various use cases. Let me know if you need further assistance!

You can download the logic app template from the estudy247 GitHub repository – la-test-csvtable-10

Post a comment

Leave a Comment

Scroll to Top