1

When I try to create an order, I get the error 400, can someone help me?

Things that may help you guys help me

  • I'm using NodeJS with Express
  • Data that I'm trying to post
    {
      "entity": {
        "base_grand_total": 10,
        "customer_email": "teste@teste.com",
        "grand_total": 10,
        "items": [
          {
            "sku": "PXL-TL-PRETO-1598467196"
          }
        ]
        }
    }
  • This is my userController.js (only the post order part)
const Magento = require('magento-api-rest').default;

const client = new Magento({
  'url': process.env.URL,
  'consumerKey': process.env.COMSUMERKEY,
  'consumerSecret': process.env.CONSUMERSECRET,
  'accessToken': process.env.ACCESSTOKEN,
  'tokenSecret': process.env.TOKENSECRET,
  'sha': 256
});

module.exports = {
  async createOrder(req, res) {
    const { entity } = req.body;

    try {
      await client.post('orders', { entity });
      res.send(req.body);
    } catch(e) {
      res.send(e);
    }
  },

};
  • The error
{
    "message": "Request failed with status code 400",
    "name": "Error",
    "stack": "Error: Request failed with status code 400\n    at createError (/home/jhonny/Área de Trabalho/Pixls-master/Backend/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/home/jhonny/Área de Trabalho/Pixls-master/Backend/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/home/jhonny/Área de Trabalho/Pixls-master/Backend/node_modules/axios/lib/adapters/http.js:236:11)\n    at IncomingMessage.emit (events.js:327:22)\n    at endReadableNT (_stream_readable.js:1220:12)\n    at processTicksAndRejections (internal/process/task_queues.js:84:21)",
    "config": {
        "url": "http://magento-11707-0.cloudclusters.net/rest/V1/orders",
        "method": "post",
        "data": "{\"entity\":{\"base_grand_total\":10,\"customer_email\":\"teste@teste.com\",\"grand_total\":10,\"items\":[{\"sku\":\"PXL-TL-PRETO-1598467196\"}]}}",
        "headers": {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Authorization": "OAuth oauth_consumer_key=\"fnklgt4yjjlo1xj08zjmckuiqb5b0b9s\", oauth_nonce=\"pi7UZld5OSMcWuLCuWv3KJowR8vWj0GF\", oauth_signature=\"ft7RdJLI%2FQtSj3eLd2eyICCmHaGJVRgPuDcK66Nku4o%3D\", oauth_signature_method=\"HMAC-SHA256\", oauth_timestamp=\"1598973019\", oauth_token=\"oanc0ajzw7a1gtma4l3gmgpx7a4f4l42\", oauth_version=\"1.0\"",
            "User-Agent": "Magento REST API - JS Client/2.0.3",
            "Content-Length": 130
        },
        "transformRequest": [
            null
        ],
        "transformResponse": [
            null
        ],
        "timeout": 0,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.