In this post I will show the steps to call Cloud(Power Automate) flow from Javascript. I will send a JSON request body to my flow and get a JSON response body back. We will do that in 3 simple steps. Let’s start.
Step 1 – Create a Power Automate Flow
Go to https://make.powerautomate.com/ and choose your environment that you want your flow to run. Select Create from the left navigation. Select “Instant cloud flow” and choose “When a HTTP request is received” as your trigger.
To send data to your flow, you need to generate your input schema. If you don’t have a schema, the flow trigger generates you one based on your sample payload. Expand your trigger action and click “Use sample payload to generate schema” and fill with your sample json string that you will send later.
To get a response back from your flow, add a “Response” action to your flow and fill “Status Code“, “Headers” and “Body“ as you desire. The data you put here will return you as response later in javascript code.
Step 2 – Copy Your “HTTP POST URL”
When you save your flow, your trigger action will generate a “HTTP POST URL” to call your flow. We will use that URL to send POST request from our code.
STEP 3 – Configure the Javascript Code
You can use the below code to call your flow. Don’t forget to change flowURL and request body . We use “JSON.parse(body)” to convert our JavaScript object to JSON string. The XMLHttpRequest sends the request as async and get the response back. You can read the response with “this.response” parameter.
No comments:
Post a Comment