Skip to content

Conversation

@MaximLogic
Copy link

Description (*)

According to issue magento/magento2#38154, the /rest/V1/inventory/source-items POST API endpoint was accepting requests with non-existent SKUs and returning 200 OK status code without any validation errors. In Inventory\Model\SourceItem\Validator\SkuValidator, validation only checked if SKU is not empty and doesn't have leading/trailing spaces, but didn't verify if a product with that SKU actually exists in the catalog.

I've added validateSkuExists() method into Inventory\Model\SourceItem\Validator\SkuValidator, that tries to load product by given SKU,and in case of failure, it catches NoSuchEntityException and returns validation error "Product with SKU <given_sku> does not exist."

Fixed Issues (if relevant)

  1. Fixes Getting success message after sending invalid SKU for the inventory/source-items API magento2#38154

Prerequisites: Have Magento installed with magento/inventory-metapackage and at least one product in store (e.g., SKU "24-MB01")

Manual testing scenarios (*)

  1. Get API token:
    curl --location 'http://your-magento.local/rest/V1/integration/admin/token' \
    --header 'Content-Type: application/json' \
    --data '{"username":"admin","password":"your-password"}'
    
  2. Test with non-existent SKU:
Screenshot 2026-01-09 at 16 36 05

Expected result: API returns 400 Bad Request status, Error message:
{"message":"Validation Failed","errors":[{"message":"Product with SKU \"sfasdfasd\" does not exist.","parameters":[]}]}

  1. Test with existing SKU:
Screenshot 2026-01-09 at 16 38 30 Expected result: API returns 200 OK, Source item quantity is updated successfully

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

… SKU for the inventory/source-items API

- added validation for existing SKUs on request processing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

Getting success message after sending invalid SKU for the inventory/source-items API

1 participant