web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Web API Request Respon...
Power Pages
Unanswered

Web API Request Response 204 on POST

(0) ShareShare
ReportReport
Posted on by 40

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>

 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    1,488 Super User 2024 Season 1 on at

    according to the documentation, you should put "entityid" for the getResponseHeader, so the code should be

     let newInvoice = xhr.getResponseHeader("entityid");

    the parameters of success do not contain directly the headers, but you can see the response headers of the call under the Network tab of Browser developers tools (press F12).
    so if entityid doesn't work, press F12, go to Network, recall your page and the call to /_api/obj_invoices will appear and see the response headers you are receiving.

    If after this test you can report your findings here I am interested regarding this. thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard