Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

D365 Dataverse API not return the create object

Posted on by 6
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,074 Super User 2024 Season 1 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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,316 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans