Hello,
I am having a weird issue when using a Power Automate flow from Power Pages.
In trying to troubleshoot it, I tried to create a simplified example of what I am trying to achieve.
In this example, I would like to pass a json object to the cloud flow.
For the sake of this example my json object is: {"emailAddress": "user@test.com","emailBody": "Hello World"}
I have created a cloud flow that accepts a json object, parses the json to extract email and sends an email to the email address and uses the second variable for the email body.
The flow has been tested by Manually inputting the Json object and it executed successfully.
If Iaunch the flow by clicking on the button on my page, the event triggers, but I receive and error 400 (Bad Request) if I have a send email action in the flow.
If I remove the send email action in the flow, when I look at the incoming parameters as received by the first action, all is fine:
"body": {
"siteId": "'.GUID",
"siteUrl": "https://'mysite.powerappsportals.com",
"userId": "00000000-0000-0000-0000-000000000000",
"text": "{\"emailAddress\":\"user@test.com\",\"emailBody\":\"Hello World\"}"
}
Here is the code I am using:
$(document).ready(function () {
$('#i0o3hn').click(function () {
var flowUrl = "/_api/cloudflow/v1.0/trigger/0c13ec47-d97a-58f5-10b8-332e9e18809f";
var emailData = { "emailAddress": "user@test.com","emailBody": "Hello World" };
var stringifiedEmailData = JSON.stringify(emailData);
var data = {};
data["text"] = stringifiedEmailData;
console.log("data",data);
var payload = {};
payload.eventData = JSON.stringify(data);
console.log("payload:", payload);
shell
.ajaxSafePost({
type: "POST",
contentType: "application/json",
url: flowUrl,
data: JSON.stringify(payload),
processData: false,
global: false,
})
.done(function (response) {
console.log("response", response);
})
.fail(function () {
alert("failed");
});
});
});
If I was to remove the send email step of that flow and simply return the result of the parsed variables to my page, the values return correctly to the page in a console.log message.
I have attached a screenshot of the flow I am using.
Thank you.