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
@engcom-Hotel
Copy link
Collaborator

@magento run all tests

@engcom-Hotel engcom-Hotel self-requested a review January 21, 2026 10:30
@engcom-Hotel engcom-Hotel moved this from Ready for Review to Review in Progress in Inventory - Pull Request Progress Jan 21, 2026
Copy link
Collaborator

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @MaximLogic,

Thank your for the contribution!

Please refer to the below review comments.

@engcom-Hotel engcom-Hotel moved this from Review in Progress to Changes Requested in Inventory - Pull Request Progress Jan 21, 2026
… SKU for the inventory/source-items API

- reverted copyright change
- added $productRepository initialisation via Object Manager if null
@engcom-Hotel
Copy link
Collaborator

@magento run all tests

Copy link
Collaborator

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @MaximLogic for making the changes!

It seems some automated tests are failing due to the PR changes, please fix those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Changes Requested

Development

Successfully merging this pull request may close these issues.

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

2 participants