Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Unanswered

D365 Dataverse API not return the create object

Posted on by 2
Hello Everyone,
 
I need help with this problem, i am using javascript to create registries in a dataverse entity, the creation its ok, but the response is 204 not content... i have been reading a lot of forums and questions, all of them said that i need to put Prefer: return=representation as a request header, i already put that header but the response is the same... i know that the response header odata has the id of the created item, but i need other information...
 
(function (webapi, $) {
  function safeAjax(ajaxOptions) {
    var deferredAjax = $.Deferred();
 
    // Obtener el token y luego hacer la solicitud
    shell.getTokenDeferred().done(function (token) {
      // Agregar el token a las cabeceras
      if (!ajaxOptions.headers) {
        ajaxOptions.headers = {
          "__RequestVerificationToken": token,
          "Prefer": "return=representation"  // Añadir Prefer aquí
        };
      } else {
        ajaxOptions.headers["__RequestVerificationToken"] = token;
        ajaxOptions.headers["Prefer"] = "return=representation";  // Añadir Prefer aquí también
      }
 
      // Ejecutar la solicitud AJAX
      $.ajax(ajaxOptions)
        .done(function (data, textStatus, jqXHR) {
          // Validar sesión o cualquier lógica necesaria
          validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
        })
        .fail(deferredAjax.reject);
    }).fail(function () {
      // En caso de fallo al obtener el token
      deferredAjax.rejectWith(this, arguments);
    });
 
    return deferredAjax.promise();
  }
 
  // Exponer la función safeAjax
  webapi.safeAjax = safeAjax;
})(window.webapi = window.webapi || {}, jQuery);
 
const response = await webapi.safeAjax({
      type: "POST",
      url: "/_api/cr9c9_tbl_solicituds",
      contentType: "application/json",
      data: JSON.stringify(dataSolicitud)
});


 


Response: 
 
/_api/cr9c9_tbl_solicituds
Request Method:
POST
Status Code:
204 No Content
Remote Address:
20.206.176.1:443
 
  • Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    D365 Dataverse API not return the create object
    did you verify inside the network tab of the browser if the header is passed or not?

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,572 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,706 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans