Hello!
I'm using the Web API in Power Apps Portals to create a new record upon click of a button, then I'm trying to get it to call a second function passing the guid of the new record, so I can relate records from another table (N:N).
The problem is that my response always comes back successful (and it is, the record is created properly) but empty. I seem to get a 204- no content response each time, so I can't get the GUID of the record I just created. I have tried getting all details of the response (res, status, xhr) but everything comes back undefined or null. If anyone could offer some advice that would be great!
Here is my code:
{% include 'AJAX Wrapper' %}
<script>
//Create Invoice
function createInvoice() {
webapi.safeAjax({
type: "POST",
Accept: "application/json",
url: "/_api/obj_invoices",
contentType: "application/json",
data: JSON.stringify({
"obj_subtotal": subtotalValue,
"obj_Registration@odata.bind": "/cref8_registrations({{ request.params.id }})",
"obj_CompetitionLocation@odata.bind": "/cref8_competitionlocations({{ request.params.compLoc }})",
"obj_Account@odata.bind": "/accounts({{ request.params.acc }})"
}),
success: function (res, status, xhr) {
let newInvoice = xhr.getResponseHeader("obj_invoiceid");
relateDiscounts(newInvoice);
console.log(res);
}
});
}
function relateDiscounts(InvoiceID) {
for (let x in discount_array){
webapi.safeAjax({
type: "POST",
Accept: "application/json",
url: "/_api/obj_invoices(" + InvoiceID + ")/obj_Invoice_obj_Discounts_obj_Discounts/$ref",
contentType: "application/json",
data: JSON.stringify({
"@odata.id":"/_api/obj_discountses(" + discount_array[x] + ")"
}),
success: function (res, status, xhr) {
console.log("entityID: "+ xhr.getResponseHeader("obj_discountsid"))
}
})
};
};
</script>

Report
All responses (
Answers (