0

I'm trying to set the position of an existing product inside a category via REST API. Currently all products have a position of 0.

The endpoint I'm using is POST /V1​/products.

The json body:

{
  "product": {
    "sku": "1234567",
    "extension_attributes": {
      "category_links": [
        {
          "position": 5,
          "category_id": 71
        }
      ]
    }
  }
}

This gives me the message The product was unable to be saved. Please try again.

Trying the same POST but with position 0 is successful. Any position other than 0 does not work.

The full trace of the error is:

#0 [...]/vendor/magento/module-catalog/Model/ProductRepository.php(628): Magento\Catalog\Model\ProductRepository->saveProduct(Object(Magento\Catalog\Model\Product\Interceptor))
#1 [...]/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Catalog\Model\ProductRepository->save(Object(Magento\Catalog\Model\Product\Interceptor), false)
#2 [...]/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Catalog\Model\ProductRepository\Interceptor->___callParent('save', Array)
#3 [...]/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Catalog\Model\ProductRepository\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Product\Interceptor), false)
#4 [...]/generated/code/Magento/Catalog/Model/ProductRepository/Interceptor.php(52): Magento\Catalog\Model\ProductRepository\Interceptor->___callPlugins('save', Array, Array)
#5 [internal function]: Magento\Catalog\Model\ProductRepository\Interceptor->save(Object(Magento\Catalog\Model\Product\Interceptor), false)
#6 [...]/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(95): call_user_func_array(Array, Array)
#7 [...]/vendor/magento/module-webapi/Controller/Rest.php(188): Magento\Webapi\Controller\Rest\SynchronousRequestProcessor->process(Object(Magento\Framework\Webapi\Rest\Request\Proxy))
#8 [...]/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#9 [...]/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Webapi\Controller\Rest\Interceptor->___callParent('dispatch', Array)
#10 [...]/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Webapi\Controller\Rest\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#11 [...]/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(26): Magento\Webapi\Controller\Rest\Interceptor->___callPlugins('dispatch', Array, Array)
#12 [...]/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#13 [...]/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch()
#14 [...]/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http\Interceptor->launch()
#15 [...]/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#16 {main}

Has anyone experienced a similar issue?

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.