How trigger a MS flow from an application in JavaScript/jQuery?

 

Trigger a  MS Flow Using Jquery/JavaScript:

To trigger an MS Flow first we need to create an workflow. Next we need to obtain its URL for triggering it. In below example, we are starting a workflow which is taking email address, email subject and email body as parameter and sending mail to email of related user.

//This function triggers the microsoft flow 

function startMSFlow() { 

        var httpPostUrl = "obtain URL from MS flow"; 

        var postData = { 

            emailadress:'raju@testdev.com', // Object keys must be similar as you used in the MS flow

            emailSubject:'Testing Raju', 

            emailBody:'Hello User\n Welcome, You just trigger a MS Flow'

            };

          $.ajax({

          url: httpPostUrl,

          method: "POST",

          crossDomain:true,

          async:false,

          processData:false,

          headers: {  

                 "content-type": "application/json", 

                    "cache-control": "no-cache" 

            },  

          data: JSON.stringify(postData), 

          success: function (data) {

           console.log(data);

            console.log('MS Flow triggered successfully');

          },

          error: function (error) {

            // error handler code goes here

            console.log(error)

          }

        }); 

    } 

startMSFlow();


Output:
As output user will receive an email as shown below




Comments

Popular posts from this blog

Get list item entity type full name of a SharePoint list using REST API

Get SharePoint list name by GUID

Get Current Web Logged In User of SharePoint Site in jQuery