Project

Practical Guide to Implementing Microsoft Forms Webhooks

A step-by-step project on how to effectively implement and integrate Microsoft Forms Webhooks using Power Automate.

Empty image or helper icon

Practical Guide to Implementing Microsoft Forms Webhooks

Description

This project provides a comprehensive guide to understanding and implementing Microsoft Forms Webhooks. By the end of the project, users will be familiar with setting up a webhook, monitoring form responses, and automating actions based on received data. Each curriculum unit is designed to build on the previous one, ensuring a thorough understanding of the entire process.

The original prompt:

what is the name of the Microsoft forms form in the code below:

{ "type": "OpenApiConnectionWebhook", "inputs": { "parameters": { "form_id": "qJYe29qjKkSTCyNcrCTNXNpeZTl1hZ1AluK2Z69q4xlUMDBTSTNDWTVFU1lBWEhZMENZNlBCWjdZVy4u" }, "host": { "apiId": "/providers/Microsoft.PowerApps/apis/shared_microsoftforms", "connection": "shared_microsoftforms", "operationId": "CreateFormWebhook" } }, "splitOn": "@triggerOutputs()?['body/value']", "metadata": { "operationMetadataId": "afb9c398-f512-4edb-8f23-b72ecb3b47f7" } }

Understanding Microsoft Forms and Webhooks

Introduction

Microsoft Forms is a tool that allows users to create surveys, quizzes, and polls. Webhooks allow you to send real-time data from one application to another when an event occurs. This guide will focus on integrating Microsoft Forms with Webhooks using Power Automate to automate workflows.

Prerequisites

  1. Microsoft 365 Account: Ensure you have a valid Microsoft 365 account.
  2. Microsoft Forms: Create a form using Microsoft Forms.
  3. Power Automate Access: Access to Microsoft Power Automate to create flows.
  4. Webhook Service URL: An endpoint that will receive data from the webhook.

Step-by-Step Implementation

Step 1: Create a Form in Microsoft Forms

  1. Go to Microsoft Forms: Open Microsoft Forms.
  2. Create a New Form: Click on "New Form."
  3. Add Questions: Add the necessary questions for your survey or quiz.
  4. Share Form: Click on the "Share" button to get the unique form URL.

Step 2: Set Up Power Automate Flow

  1. Sign in to Power Automate: Open Power Automate and sign in with your Microsoft 365 account.

Step 3: Create a New Automated Flow

  1. Create a New Flow:

    • Click on "Create" in the left-hand menu.
    • Select "Automated cloud flow."
    • Name your flow (e.g., "Form to Webhook").
  2. Choose a trigger:

    • In the "Choose your flow's trigger" search box, type "Microsoft Forms."
    • Select "When a new response is submitted" as the trigger.
    • Click "Create."
  3. Configure Trigger:

    • Select the form you created from the dropdown menu.

Step 4: Add Actions to the Flow

  1. Get Response Details:

    • Click on "New step."
    • Search for "Microsoft Forms" and select "Get response details."
    • Configure the action:
      • Form ID: Select the form you created.
      • Response ID: Set to "Response Id" from the previous trigger.
  2. Send Data to Webhook:

    • Click on "New step."
    • Search for "HTTP" and select "HTTP."
    • Configure the HTTP action:
      • Method: POST
      • URI: Enter your Webhook Service URL (e.g., https://your-webhook-url.com)
      • Headers: Add headers if required by your webhook (e.g., Content-Type: application/json)
      • Body: Construct a JSON object with the form data.

Example JSON Body:

{
  "response_id": "@{triggerOutputs()?['body/responseId']}",
  "responses": {
    "question1": "@{outputs('Get_response_details')?['body/r1']}",
    "question2": "@{outputs('Get_response_details')?['body/r2']}"
  }
}

Step 5: Test the Flow

  1. Save the Flow: Click on "Save."
  2. Submit a Response: Open the form URL you shared earlier and submit a response.
  3. Check Execution:
    • Go back to Power Automate.
    • Click on your flow.
    • Go to the "Run History" to check if the flow was executed successfully.

Conclusion

By following the steps outlined above, you have successfully set up a flow in Power Automate that triggers when a new response is submitted in Microsoft Forms and sends that data to a specified Webhook endpoint. This automation allows seamless data integration and timely reactions to new form submissions, enhancing workflow efficiency.


This concludes the first unit of the curriculum. Continue to explore more functionalities to further enrich your project based on this foundation.

Setting Up the Microsoft Forms Webhook

Power Automate Setup to Integrate Microsoft Forms and Webhook

Step 1: Create a New Flow

  1. Navigate to Power Automate:

  2. Create a New Flow:

    • Click on "Create" from the left-side menu.
    • Select "Automated cloud flow".

Step 2: Configure the Trigger

  1. Name Your Flow:

    • Enter a name for your flow.
    • In "Choose your flow’s trigger" search box, type "Microsoft Forms" and select "When a new response is submitted".
  2. Connect Your Form:

    • If not already connected, click on "Sign in" to connect your Microsoft Forms account.
    • Select the form you want to integrate from the drop-down list.
  3. Add an Action:

    • Click on "+ New step".
    • Search for "Microsoft Forms" and select “Get response details”.
    • Configure the action with your form ID and Response ID (dynamic content).

Step 3: Set up the Webhook Action

  1. Add a 'HTTP' Action:

    • Click on "+ New step".
    • Search for "HTTP" and select the "HTTP" action.
  2. Configure the 'HTTP' Action:

    • Method: POST
    • URI: Enter the URL of your webhook endpoint.
    • Headers: (Optional, if your webhook requires headers)
      {
        "Content-Type": "application/json"
      }
    • Body: Construct the JSON payload using the dynamic content from Microsoft Forms response details. For example, if you have fields Question1 and Question2 in your form:
      {
        "response_id": "@{outputs('Get_response_details')?['body/responseId']}",
        "question_1": "@{outputs('Get_response_details')?['body/Question1']}",
        "question_2": "@{outputs('Get_response_details')?['body/Question2']}"
      }

Step 4: Save and Test the Flow

  1. Save Your Flow:

    • Click on the "Save" button located at the top-right corner of the screen.
  2. Test Your Flow:

    • Fill out the form and submit a response.
    • Navigate back to Power Automate and go to "My flows".
    • Click on your flow name.
    • Under the 28-day run history, check the status of your flow to ensure it ran successfully.
    • Check your webhook endpoint to verify that it received the payload as expected.

Example JSON Body

Here’s an example JSON structure that could be used for the HTTP action body:

{
  "response_id": "@{outputs('Get_response_details')?['body/responseId']}",
  "email": "@{outputs('Get_response_details')?['body/email']}",
  "feedback": "@{outputs('Get_response_details')?['body/feedback']}"
}

Conclusion

Your Power Automate flow should now be configured to send data from Microsoft Forms to your specified webhook endpoint whenever a new form response is submitted. This setup facilitates automation and real-time data integration seamlessly.

Step 3: Integrating Webhooks with Power Automate to Handle Microsoft Forms Responses

Overview

This step demonstrates how to use Power Automate to process data received from a Microsoft Forms webhook. Power Automate will listen to the webhook trigger, process the incoming data, and perform follow-up actions.

Practical Implementation

Step-by-Step Guide:

  1. Create a New Flow in Power Automate

    • Navigate to Power Automate.

    • Click on Create in the left navigation pane.

    • Select Automated Flow.

  2. Define the Trigger for the Flow

    • Search for "When a HTTP request is received" and select it as the trigger.

    • The system will generate a URL for the webhook after the flow is saved.

  3. Set Up the Trigger Schema

    • Click on the Generate from Sample button.

    • Paste a sample JSON payload you expect from Microsoft Forms. Example:

      {
        "responseId": "0123456789",
        "submittedBy": {
            "userId": "user@example.com"
        },
        "formData": {
            "field1": "value1",
            "field2": "value2"
        }
      }
    • Click Done.

  4. Add Actions to Process Incoming Data

    • Click on + New Step.

    • Parse JSON: Configure this action to interpret the webhook data.

      • For Content, select the body from the trigger.
      • For Schema, use the same sample JSON payload or manually define the schema.
    • Add A New Step to Process Data: This could involve storing the data in SharePoint, sending an email, or any other action based on your requirement.

      Example: Storing data into a SharePoint List

      • Add a step "Create item" in SharePoint.
      • Configure the connections and select the relevant SharePoint site and list.
      • Map the form fields to the corresponding SharePoint list columns. Example:
        • Title: body('Parse_JSON')?['formData']?['field1']
        • Other Column: body('Parse_JSON')?['formData']?['field2']
  5. Test the Flow

    • Save the flow and copy the HTTP POST URL provided.

    • Configure Microsoft Forms (or another tool/service) to send a POST request to this URL with the form data.

    • Submit a response in Microsoft Forms to trigger the flow and check if the follow-up actions are performed as expected.

  6. Monitor and Debug

    • Navigate to My flows in Power Automate.

    • Click on the flow name to see the run history.

    • Check the latest run to ensure the flow executed properly and debug if there are any issues.

Notes

  • Ensure that the incoming data schema matches the actual data being posted by the webhook to avoid JSON parsing errors.
  • Customize follow-up actions based on specific project needs.

Monitoring and Handling Form Responses

Here’s a practical implementation of handling and monitoring form responses using Microsoft Forms Webhooks integrated with Power Automate. At this point, I assume you have already set up the webhook and integrated it with Power Automate.

Step 1: Create a Flow in Power Automate to Handle Form Responses

  1. Trigger Setup:

    • Define a trigger for when a new response is received from the webhook.

      Trigger: When a new response is submitted (Microsoft Forms)
  2. Initialize Variables (Optional):

    • You may need variables for handling responses, especially if you aim to process or store the responses systematically.

      Action: Initialize Variable
      Name: formResponse
      Type: Object
      Value: Add the response object (dynamic content) here
  3. Parse JSON:

    • Use the ‘Parse JSON’ action to parse the response.

      Action: Parse JSON
      Content: @triggerBody()['responses'][0]
      Schema: {
          "type": "object",
          "properties": {
              "question1": {
                  "type": "string"
              },
              "question2": {
                  "type": "string"
              },
              ...
          }
      }
  4. Store or Process Responses:

    • Based on requirements, respond with storing or processing the information. Here is an example to save it to a SharePoint list or Database.
    Action: Create Item
    Site Address: Your SharePoint site address
    List Name: Your list name
    Title: @outputs('Parse_JSON')?['question1']
    OtherFields: Additional responses (map the parsed responses to corresponding fields)
  5. Send Confirmation Email:

    • If a confirmation email is required, use the following steps to set up email notifications.
    Action: Send an email
    To: respondentEmail@example.com
    Subject: "Form Response Received"
    Body: "Dear Respondent, your form submission has been received. Details: @variables('formResponse')"

Step 2: Monitoring

  1. Log Responses:

    • Create a log of responses for monitoring purposes. You can use a spreadsheet, database, or any logging service you have.
    Action: Append to CSV
    File Name: FormResponses.csv
    Content: Add the parsed response content
  2. Error Handling:

    • Set up error handling to handle any potential issues and ensure no data is lost.
    Action: Scope (or Apply to each)
    Expression: Add your response processing steps
    On Failure: Notify admin, log error, etc.

    Example for a failure condition:

    Action: Send an email
    To: admin@example.com
    Subject: "Error in Processing Form Response"
    Body: "An error occurred while processing the response. Details: @workflow().Error"
  3. Dashboard for Monitoring (Optional):

    • If real-time monitoring is required, integrate with Power BI to create a dashboard.
    - Use Power BI dataset linked to your SharePoint list/database where responses are stored.
    - Update Power BI dashboard with response data.

Conclusion

This implementation outline should enable real-time monitoring and handling of form responses using Microsoft Forms, Webhooks, and Power Automate. Each step is aimed at ensuring seamless integration and streamlined processing of responses. Ensure to test the entire flow thoroughly in a controlled environment before applying it in production.

Automating Actions Based on Webhook Data

In this part of the project, we will automate specific actions based on the data received from the Microsoft Forms Webhook using Power Automate. Assuming that the webhook is already set up and the data is being received correctly, we create a flow in Power Automate to trigger actions based on the incoming data.

Steps to Implement Automations in Power Automate

Step 1: Create a New Flow

  1. Log in to Power Automate.
  2. Click on "Create" from the left-hand menu.
  3. Select "Automated flow".

Step 2: Define the Trigger

  1. In the "Build an automated flow" screen, search for the "When a HTTP request is received" trigger (common for webhook integration).
  2. Add this trigger to the flow.

Step 3: Parse the Webhook Data

  1. After the trigger, add a new step.
  2. Search for "Data Operation" and choose "Parse JSON".
  3. Configure the Parse JSON action:
    • Content: Select the "Body" from the trigger output.
    • Schema: Generate a schema using a sample payload you expect to receive. This can be done automatically if you click on "Use sample payload to generate schema".

Step 4: Add Conditional Logic

  1. Add a new step.
  2. Search for "Condition" and add it.
  3. Configure the Condition action:
    • Under "Choose a value": Select the specific field from the parsed JSON data you want to use for your condition (e.g., responses.questionID).
    • Select the condition type (e.g., "equals").
    • Provide the condition value (e.g., a specific answer).

Step 5: Define Actions Based on Conditions

If Condition is True

  1. In the "If yes" branch, add the actions you want to automate. For example:
    • Send an Email:

      1. Add a new step.
      2. Search for "Outlook" and select "Send an email (V2)".
      3. Configure the email settings (To, Subject, Body) using dynamic content from your parsed JSON data.
    • Create a Record in a Database:

      1. Add a new step.
      2. Search for your database connector (e.g., SQL Server, SharePoint, etc.).
      3. Configure the insert action with the necessary fields.

If Condition is False

  1. In the "If no" branch, add alternative actions if needed. This branch can be left empty if no actions are required when the condition is not met.

Step 6: Save and Test the Flow

  1. Click on "Save" to save your flow.
  2. Test the flow by submitting a new response through the Microsoft Form and observe the automated actions.

Example Flow JSON

Here is an example JSON of a basic flow structure:

{
  "definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
      "Parse_JSON": {
        "type": "ParseJson",
        "inputs": {
          "content": "@triggerBody()",
          "schema": {
            "properties": {
              "responses": {
                "type": "object",
                "properties": {
                  "questionID": {
                    "type": "string"
                  }
                }
              }
            },
            "type": "object"
          }
        }
      },
      "Condition": {
        "type": "If",
        "inputs": {
          "condition": {
            "and": [
              {
                "equals": [
                  "@body('Parse_JSON')?['responses']?['questionID']",
                  "desired_answer"
                ]
              }
            ]
          },
          "actions": {
            "Send_an_email_(V2)": {
              "type": "SendEmail",
              "inputs": {
                "to": "example@example.com",
                "subject": "Form Response Notification",
                "body": "A user has submitted a response with the desired answer."
              }
            }
          }
        }
      }
    },
    "triggers": {
      "When_a_HTTP_request_is_received": {
        "type": "Request",
        "inputs": {}
      }
    }
  },
  "kind": "Stateful"
}

Replace "desired_answer", "example@example.com", and other placeholders with real values relevant to your scenario. Save, activate, and your automated actions should now process incoming webhook data appropriately!