Hi Folks,
Recently, I started using powerapps portal web api. My requirement is to associate a custom entity lookup on create (POST) and to update statuscode using PATCH. For both operations I am getting 400-Bad Request as response.
I created a web template 'Wrapper AJAX Template' to use in my "Payment Success" Web Template. Please see my below code. I have highlighted the code where I am making a call to the api. See if you can help me with this!!! Thank you in advance
{% assign invoice = entities['heblegpo_invoice'][request.params.invoiceid] %}
{% include 'Wrapper AJAX Template' %}
<html>
<head>
</head>
<link href="">fonts.googleapis.com/css rel="stylesheet">
<style>
h1 {
color: #88B04B;
font-family: "Nunito Sans", "Helvetica Neue", sans-serif;
font-weight: 900;
font-size: 40px;
margin-bottom: 10px;
margin-left: 109px;
}
p {
color: #404F5E;
font-family: "Nunito Sans", "Helvetica Neue", sans-serif;
font-size:20px;
margin: 0;
}
p2 {
color: #404F5E;
font-family: "Nunito Sans", "Helvetica Neue", sans-serif;
font-size:20px;
margin-left: 198px;
}
i {
color: #9ABC66;
font-size: 100px;
line-height: 200px;
margin-left:46px;
}
.card {
background: white;
padding: 60px;
border-radius: 4px;
box-shadow: 0 2px 18px #C8D0D8;
display: inline-block;
margin-left: 407px;
margin-top: 25px;
}
#spinner:not([hidden]) {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
}
#spinner::after {
content: "";
width: 80px;
height: 80px;
border: 2px solid #f3f3f3;
border-top: 3px solid #f25a41;
border-radius: 100%;
will-change: transform;
animation: spin 1s infinite linear
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
<script type="text/javascript">
//Create a Billing record in CRM against the paid invoice
function CreateBillingRecord(){
var invoice_id = "{{invoice.heblegpo_invoiceid}}";
var invoice_status = "{{invoice.heblegpo_invoicestatus}}";
const spinner = document.getElementById("spinner");
var invoice_total_amount = "{{ invoice['heblegpo_totalamount'] }}";
invoice_total_amount = parseFloat(invoice_total_amount);
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
if(invoice_status != "Paid"){
spinner.removeAttribute('hidden');
webapi.safeAjax({
type: "POST",
url: "/_api/heblegpo_billings",
contentType: "application/json",
data: JSON.stringify({
"heblegpo_name": "Billing_" + invoice_id,
"heblegpo_billnumber": "bill_no_" + "{{invoice.heblegpo_invoice}}",
"heblegpo_totalpaidamount": invoice_total_amount,
"heblegpo_date": today,
"heblegpo_InvoiceNumber@odata.bind": "/heblegpo_invoices("+invoice_id+")"
}),
success: function (res, status, xhr) {
spinner.setAttribute('hidden', '');
//print id of newly created entity record
var billing_id = xhr.getResponseHeader("entityid");
console.log("entityID: "+ billing_id);
}
});
UpdateInvoiceStatus(spinner);
}
}
//Update Invoice Status to Paid
function UpdateInvoiceStatus(spinner){
var invoice_id = "{{invoice.heblegpo_invoiceid}}";
var invoice_status = "{{invoice.heblegpo_invoicestatus}}";
if(invoice_status != "Paid"){
spinner.removeAttribute('hidden');
webapi.safeAjax({
type: "PATCH",
url: "/_api/heblegpo_invoices("+invoice_id+")",
contentType: "application/json",
data: JSON.stringify({
"statuscode": 247340001
}),
success: function (res) {
spinner.setAttribute('hidden', '');
//print id of newly created entity record
console.log(res)
}
});
}
}
</script>
<body onload="CreateBillingRecord();">
<div class="card">
<div hidden="" id="spinner"></div>
<div style="border-radius:200px; height:200px; width:200px; background: #F8FAF5; margin:0 auto;">
<i class="checkmark">✓</i>
</div>
<h1>Payment Success</h1>
<p>We received your purchase request for the invoice {{ invoice.heblegpo_invoice }}</p>
<p2>Thank you!</p2>
</div>
</body>
</html>
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156