medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.93k stars 2.6k forks source link

Docs(Code Issue): Missing Product Options in Admin API Product Creation with Additional Data Example #9632

Closed VrajPatelK closed 4 weeks ago

VrajPatelK commented 4 weeks ago

What Medusa version and documentation are you using?

v2

Preliminary Checks

Issue Summary

In the Medusa documentation, the current curl example for creating a product via the Admin API is missing the options field, which is required for the product. This results in an error when attempting to create a product.

Current Example:

curl -X POST 'http://localhost:9000/admin/products' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {token}' \
--data '{
    "title": "Product 1",
    "additional_data": {
        "brand_id": "01J7AX9ES4X113HKY6C681KDZ2J"
    }
}'

Expected Example:

curl -X POST 'http://localhost:9000/admin/products' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {your_token}' \
-d '{
  "title": "Product 1",
  "options": [
    {
      "title": "Default option",
      "values": ["Default option value"]
    }
  ],
  "additional_data": {
    "brand_id": "01J7AX9ES4X113HKY6C681KDZ2J"
  }
}'

This missing field leads to the following error:

Code Example:

{
  "type": "invalid_data",
  "message": "Product options are not provided for: [Product 1]."
}

Steps to Reproduce:

  1. Run the provided curl command:
curl -X POST 'http://localhost:9000/admin/products' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {token}' \
--data '{
    "title": "Product 1",
    "additional_data": {
        "brand_id": "01J7AX9ES4X113HKY6C681KDZ2J"
    }
}'
  1. Observe the error message indicating that product options are missing.

How can this issue be resolved?

Resolution Suggestion:

Update the documentation with the correct curl example, including the options field:

curl -X POST 'http://localhost:9000/admin/products' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {your_token}' \
-d '{
  "title": "Product 1",
  "options": [
    {
      "title": "Default option",
      "values": ["Default option value"]
    }
  ],
  "additional_data": {
    "brand_id": "01J7AX9ES4X113HKY6C681KDZ2J"
  }
}'

Are you interested in working on this issue?

shahednasser commented 4 weeks ago

Thanks for submitting this issue @VrajPatelK ! This is due to a new update that requires an option to be passed.

Will open a PR to fix it