Is inventory_behaviour working properly for REST Order Create API?

Solved

Is inventory_behaviour working properly for REST Order Create API?

SeanZ
Excursionist
15 2 4

Hi,

The inventory quantity is not decreasing when the REST order create API is called, no matter I set inventory_behaviour as decrement_ignoring_policy or decrement_obeying_policy. I saw two unsolved topics in the forum so I wonder whether it is working properly now?

My orders are all created successfully. And the request is like:

POST /admin/orders.json

array(
    'order' => array(
        'inventory_behaviour' => 'decrement_obeying_policy',
        'line_items' => array(
            0 => array(
...

 

Accepted Solution (1)
Zameer
Shopify Staff
297 31 90

This is an accepted solution.

Hey Sean,

 

The problem is that you are passing in a `product_id` for the order `line_items` instead of a `variant_id`. Since inventory is tied to variants, you need to specify the `variant_id` in order for the inventory behaviour to execute properly.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 14 (14)

alpha_lulu
Visitor
3 0 0

Did you ever solve this?

Zameer
Shopify Staff
297 31 90

Hey there,

 

The Order API should allow you to decrement inventory as you create orders, using the 'inventory_behaviour' property.

 

If you're running into any issues with that behaviour, please share a request id from the response header so we can investigate.

To learn more visit the Shopify Help Center or the Community Blog.

hcmlopes
Tourist
5 0 2

I am also experiencing issues with this. The product in question in my store has Shopify track inventory quantity.

 

Some examples requests I have made are

{
  "inventory_behavior": "decrement_obeying_policy",
  "order": {
    "line_items": [
      {
        "variant_id": 1326301970462,
        "title": "Insane Shoes",
        "quantity": 8
      }
    ],
    "customer": {
    	"id": 1128408580182
    }, 
    "currency": "USD",
    "financial_status": "paid"
  }
}

or

 

 

{
  "order": {
    "inventory_behavior": "decrement_obeying_policy",
    "line_items": [
      {
        "variant_id": 1326301970462,
        "title": "Insane Shoes",
        "quantity": 8
      }
    ],
    "customer": {
    	"id": 1128408580182
    }, 
    "currency": "USD",
    "financial_status": "paid"
  }
}

and a few others which all create the order either paid or unpaid, fulfilled or not and in every way I can imagine. I receive no error and no inventory is ever decremented from the variant id in questions.

 

 

X-Request-Id →593c3a66-4384-4d45-a15a-a6d1258e961e
 
Thank you in advance
hcmlopes
Tourist
5 0 2

I found my problem. I had "inventory_behaviour" misspelled.

 

This code properly decrements inventory

{
  "order": {
	"inventory_behaviour": "decrement_obeying_policy",
    "line_items": [
      {
        "variant_id": 1326301970462,
        "quantity": 8,
      }
    ],
    "customer": {
    	"id": 1128408580182
    }, 
    "currency": "USD",
    "financial_status": "paid"
  }
}

If you have inventory or Allow customers to purchase this product when it's out of stock then you will get the order response.

If you have no inventory then you will get a json response that looks like this

{
    "errors": {
        "line_items": [
            "Unable to reserve inventory"
        ]
    }
}
SeanZ
Excursionist
15 2 4

Could you please help me by checking this order response?

{
    "order": {
        "id": 953703399529,
...

I am 80% sure I was using decrement_obeying_policy for inventory_behaviour.

SeanZ
Excursionist
15 2 4

@Zameer Could you please help? I tried several times on a test store but it seems still not working well.

Request:

{
  "order": {
    "inventory_behaviour": "decrement_obeying_policy",
    "line_items": [
      {

Response:

{
  "order": {
    "id": 1014917890153,
Zameer
Shopify Staff
297 31 90

Hey Sean,

 

Sorry for missing your first post. I tried finding your request in our logs based on the order number you provided but I was unable to.

 

Can you please provide me with the X-Request-Id response header for one of these requests that are problematic?

To learn more visit the Shopify Help Center or the Community Blog.

SeanZ
Excursionist
15 2 4

@Zameer Thanks for the quick response! Hope you don't mind I @you many times.

I just tried another order and here's the response information:

X-Request-Id: 5bff5cfa-4241-4abc-9ba4-a9f0f8e3c1bb

Zameer
Shopify Staff
297 31 90

This is an accepted solution.

Hey Sean,

 

The problem is that you are passing in a `product_id` for the order `line_items` instead of a `variant_id`. Since inventory is tied to variants, you need to specify the `variant_id` in order for the inventory behaviour to execute properly.

To learn more visit the Shopify Help Center or the Community Blog.

SeanZ
Excursionist
15 2 4

Oh, it works perfectly.

Thank you, Zameer! You literally save the day.

DomPossebon
Tourist
6 0 1

nada

lmakris
Shopify Partner
6 0 1

It doesn't work.. how is this an accepted solution? Quantity is not decreasing.

Lee48
Visitor
2 0 0

I am not seeing 'inventory_behavior' work either.  The items are set to 'Track Quantity' and when I use the REST API to load the order, the ordered quantities do not show as 'Commited' in the inventory quantity.  I have tried different 'inventory_behavior' options and removing the product ID.  Nothing works.  Any ideas would be appreciated.

 


@Zameer wrote:

Hey Sean,

 

The problem is that you are passing in a `product_id` for the order `line_items` instead of a `variant_id`. Since inventory is tied to variants, you need to specify the `variant_id` in order for the inventory behaviour to execute properly.



This is what we are sending:

{
   "order":{
      "inventory_behavior":"decrement_obeying_policy",
      "billing_address":{
         "address1":"",
         "address2":"",
         "city":"",
         "company":"Acme Movers",
         "first_name":"Mike",
         "last_name":"Armstrong",
         "province_code":"AK",
         "zip":"",
         "country_code":"US"
      },
      "shipping_address":{
         "address1":"100 Main Street",
         "address2":"",
         "city":"Chicago",
         "company":"Acme Movers",
         "first_name":"Mike",
         "last_name":"Armstrong",
         "phone":"(888) 888-8888",
         "province_code":"IL",
         "zip":"60611-2725",
         "country_code":"US"
      },
      "buyer_accepts_marketing":false,
      "currency":"USD",
      "customer":{
         "id":0,
         "email":"mike@acmemovers.com",
         "first_name":"Mike",
         "last_name":"Armstrong"
      },
      "email":"mike@acmemovers.com",
      "line_items":[
         {
            "id":8297038905571,
            "quantity":1,
            "price":0.0,
            "sku":"STICKER",
            "variant_id":44397341704419,
            "taxable":false,
            "total_discount":0.0,
            "name":"Sticker",
            "title":"Sticker"
         }
      ],
      "note":"",
      "shipping_lines":[
         {
            "code":"NA",
            "price":0.0,
            "title":"Free Shipping"
         }
      ],
      "tax_lines":[
         {
            "price":0.0,
            "rate":0.0
         }
      ],
      "total_discounts":0.0,
      "total_line_items_price":0.0,
      "total_tax":0.0,
      "tags":""
   }
}

 

adroitdreamer
Shopify Partner
1 0 0

- I just confirmed that i needed to send the json with `inventory_behaviour` with a u

- my issue was that i misspelled it as behavior

- and that you only need to send a variant id in the line_item

 

everything is working fine now