Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

309
Vistas
axios.post is showing error "Request failed with status code 400" but same data is posted by postman

when i am post same "data-object" with same "url-link" in postman, its working and my data is post successfully in postman. but when hit request through axios, there is accoured error "Request failed with status code 400". and my data is not posting. i tried to pass data object of axios, eg, "JSON.stringify(data)" but its not working and showing error "status 400". plez solve my query....

there is axios error

const Axios = require("axios");
export const uploadImages = (data) => async (dispatch) => {
  dispatch({
    type: "UPLOAD_IMAGES_INIT",
  });
  try {
    const result = await Axios.post("http://localhost:4000/postImages", {
      "id":1,
      "name":"Flare Dress",
      "price":12000,
      "salePrice":20000,
      "discount":10,
      "pictures":[
         "/assets/images/fashion/product/1.jpg",
      ],
      "shortDetails":"Sed ut perspiciatis, unde omnis iste natu",
      "description":"Lorem Ipsum is simply dummy text of",
      "stock":16,
      "new":true,
      "sale":true,
      "category":"women",
      "colors":[
         "yellow",
      ],
      "size":[
         "M",
      ],
      "tags":[
         "nike",
      ],
      "rating":4,
      "variants":[
         {
            "color":"yellow",
            "images":"/assets/images/fashion/product/1.jpg"
         },

      ],
      "newPostImages":[
         {
            "images":"/assets/images/fashion/product/1.jpg"
         },
      ]
   });
  } catch (err) {
    const error = err.message || "Error Upload Images";
    dispatch({
      type: "UPLOAD_IMAGES_FAIL",
      payload: error,
    });
  }
};

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I got an answer to this question. There's a difference in the request structure from Postman and my code (No matter if using fetch or Axios). Yeah, it may happen that the current user does not have permissions for some entity, but in this case it's all about the following:

  • Simple answer: You have to choose cookie auth or basic auth.
  • Basic auth: base64 format for user and password.
  • Cookie auth (I'm using this option): Drupal sets a header with a session cookie when doing the login request (Postman is automatic, but in your code request, you need to include and send the same cookie for a POST or PATCH or whatever needs auth). Don't forget to send your token header also.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda