Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

D365 Dataverse API not return the create object

(3) ShareShare
ReportReport
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,087 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans