medusajs / medusa

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

Draft Orders creation through Admin API #9890

Open dupuisbenjamin opened 1 month ago

dupuisbenjamin commented 1 month ago

Bug report

Describe the bug

Hi,

When creating a Draft Order with the API, it is impossible to create it. My request input is the following:

{ 
    "shipping_methods": [],
    "email": "{{email}}",
    "region_id": "{{region_id}}",
    "currency_code": "EUR",
    "items": [
          {
                  "quantity": 1,
                  "variant_id": "{{variant_id}}"
          }
    ]
}

Which gives the error, "Sales channel sc_01J9NWRZSRXF469CB7ZH95Y95V is not associated with any stock location." (where sc_01J9NWRZSRXF469CB7ZH95Y95V is the default Medusa sales channel)

The fields in the request body are optional in the API documentation but some are still required once called.

System information

Medusa version (including plugins): v2.0.1 Node.js version: v20.17.0 Database: Postgres v10.4 Operating system: Windows 11

Steps to reproduce the behavior

  1. Prepare a POST-Request to {MEDUSA_SERVER}/admin/draft-orders
  2. Set BODY to
    
    { 
    "shipping_methods": [],
    "email": "{{email}}",
    "region_id": "{{region_id}}",
    "currency_code": "EUR",
    "items": [
          {
                  "quantity": 1,
                  "variant_id": "{{variant_id}}"
          }
    ]
    }
3. Send request 
4. You'll receive the following error

{ "type": "invalid_data", "message": "Sales channel sc_01J9NWRZSRXF469CB7ZH95Y95V is not associated with any stock location." }



### Expected behavior

I except the draft-order to be created.

### Additional context
This might be related to  #9812 due to the linkable property.
olivermrbl commented 1 month ago

@dupuisbenjamin, the error message describes the issue quite well, and, at first glance, this is expected behavior. Your sales channel (the default one) is not associated with any stock location and can, therefore, not be used to fulfill orders.

Have you tried to configure a stock location for the sales channel? You do that in Settings > Locations & Shipping in the admin dashboard.

dupuisbenjamin commented 1 month ago

@olivermrbl, thank you for your answer.

I succeed in associating a stock_location to a sales_channel through both the Admin dashboard and API! However, I still have the same error while trying to create a draft-order:

{
    "type": "invalid_data",
    "message": "Sales channel sc_01J9NWRZSRXF469CB7ZH95Y95V is not associated with any stock location."
}

My products have their field "sales_channels" with the right sales_channels_id.

sradevski commented 3 weeks ago

@dupuisbenjamin can you please check what's inside the sales_channel_stock_location table in your DB?

dupuisbenjamin commented 3 weeks ago

@sradevski Hi, here is the sales_channel_stock_location table in my DB.

image

I have noticed that the error doesn't occur when I create a draft order without items. However, my goal is to create the draft order with items, and by trying to do so the error still occurs.

I made sure the variant_id of the item in my draft order corresponded to a variant where its product has the same sales_channel linked to a stock_location (in this case I am putting sc_01J9NWRZSRXF469CB7ZH95Y95V for the sales_channel id of my products).