Skip to content

PUT/POST Rest request occasionally fail without error status code 400

Not quite sure where to start debugging, PUT/POST request occasionally without any errors in Magento logs, status code 400. The exact same request later goes through succesfully.

Example failed request:

400 PUT /rest/V1/products/9793/stockItems/1567?stockItem%5Bqty%5D=466&stockItem%5Bis_in_stock%5D=1 HTTP/2.0 varnish

Example successfull request moments later:

200 PUT /rest/V1/products/9793/stockItems/1567?stockItem%5Bqty%5D=466&stockItem%5Bis_in_stock%5D=1 HTTP/1.1 phpfpm

200 PUT /rest/V1/products/9793/stockItems/1567?stockItem%5Bqty%5D=466&stockItem%5Bis_in_stock%5D=1 HTTP/2.0 varnish

Added a log in MagentoCatalogInventoryModelStockRegistry updateStockItemBySku function, for the failed requests this function is never reached.

Thought it might have to do with Varnish, so I added a bypass, but this had no effect:

if (req.url ~ "^/rest/") {
    return (pass);
}

Using Magento 2.4.5-p11, Varnish 6.1.1.
Only happens on PUT/POST requests.

Any tips on where to start debugging?