cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
5by5T
Frequent Visitor

Web API Request Response 204 on POST

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>

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
GuidoPreite
Super User
Super User

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

View solution in original post

1 REPLY 1
GuidoPreite
Super User
Super User

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

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

MPP IDEAS updated 768x460.png

Ideas

Discover ideas and concepts from users like you for how to use Power Pages and take your work to the next level.

Carousel News & Announcements

What's New in the Community?

Check out the latest News & Events in the community!

Top Solution Authors
Users online (2,809)