Create Product With Inventory Levels?

Solved
Highlighted
Shopify Partner
9 1 2

Hello,

 

I'm simply trying to create products with variants and initial inventory levels, and I feel like I must be doing something wrong, since it's insanely complex and taking up a ton of requests.

 

Can someone please confirm that there is no way to set the initial inventory level for a product variant in the product create request?

 

Is the only way to add variant inventory levels to make a separate request to the 

admin/inventory_levels/adjust.json endpoint?

 

If this is the case, then to create a simple product with 3 variants with inventory levels, I'd have to make this series of requests:

 

1. Make a request to admin/products.json to create product with 3 variants

 

2. For every single variant, make the following requests:

 

  1. With the returned inventory_item_id, make a request to admin/inventory_items/{inventory_item_id}.json to set the tracked field to true. Otherwise, setting the inventory level does not seem to work.
  2. Make a request to /admin/inventory_levels.json?inventory_item_ids={inventory_item_id} to get a list of inventory levels which will include the required location_id field for the next request
  3. Make a request to admin/inventory_levels/adjust.json to finally update the inventory

 

Some products have 10+ variants, which would result in 20+ requests being made just to create this one product. That is really going to mess with my API rate limit since there are many users attempting to import products at the same time.

 

Am I doing this correctly, or am I missing something obvious?

 

Thank you so much,

 

 

Patrick

1 Like
Highlighted
Shopify Staff
Shopify Staff
1129 82 170

This is an accepted solution.

Hey @Patrick_Kelly2 , 

 

You should be able to set inventory at a shop's primary/default location upon product creation, but if it's a multi-location shop it'll take multiple requests to set inventory quantities correctly. You might want to look into using GraphQL if you're getting into multi-location stores. 

 

Otherwise, I just tested out this API call for a product with two variants and this is enabling inventory tracking and setting the quantity upon creation : 

 

{
  "product": {
    "title": "Burton Custom Freestyle 151",
    "body_html": "<strong>Good snowboard!</strong>",
    "vendor": "Burton",
    "product_type": "Snowboard",
    "variants": [
      {
        "option1": "First",
        "price": "10.00",
        "sku": "123",
	"inventory_management": "shopify",
	"inventory_quantity": 15
      },
      {
        "option1": "Second",
        "price": "20.00",
        "sku": "123",
	"inventory_management": "shopify",
	"inventory_quantity": 5
      }
    ]
  }
}
2 Likes
Highlighted
Shopify Partner
9 1 2
Thank you!! I appreciate your help.
0 Likes
Highlighted
Excursionist
15 1 1

When I try to POST this example I am getting RESPONSE 303 and redirected html.  

0 Likes
Highlighted
Shopify Partner
9 1 2

Hey Bob,

 

I didn't copy this exact data, but I did add the following to my request which did work for me:

 

	"inventory_management": "shopify",
	"inventory_quantity": 5

 

Have you been able to make a successful request otherwise?

 

 - Patrick 

0 Likes
Highlighted
Shopify Partner
13 0 2

Hi Josh,

Why does the Shopify API instructions not show an example of setting quantity when creating new inventory?

I see that "inventory_quantity" is depreciated for "updating" a product (update variants), but is it not depreciated for "creating" new products?

Confused as usual.

 

thanks,

Ron

0 Likes
Highlighted
Shopify Partner
43 4 8

This no longer seems to be true when creating new products?

Screenshot from 2020-03-17 16-51-17.png

And the store only has one inventory location.

Need some help or work done? Hire me!
0 Likes
Highlighted
New Member
2 0 2

{"error":"Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported. Please use the Inventory Levels API."}

0 Likes
Highlighted
Tourist
5 0 3

Josh, your solution (which solves the problem in every single way), has now been explicitly disallowed by Shopify:

 

 
{
    "error": "Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported. Please use the Inventory Levels API."
}
 
Any other solution, or did Shopify just give a giant "f-u" to everyone who uses these calls for selling unique items?
1 Like
Highlighted
New Member
1 0 0

Just bumping this thread again. Now that the approach recommended in this thread is deprecated, do API developers just need to deal with the trade-off between more product variants and longer product creation due to one-inventory-call-per-variant?

 

I realized that if product creation returns inventory_level_id in addition to inventory_item_id, then I should be able to do this in one API call via graphQL, but for now, the only approach I could find was to iterate over variants, and pull inventory_level_id's from each inventory_item_id in order to create the proper GraphQL for a bulk inventory edit.

 

Alternatively, perhaps the API quota could be increased for inventory updates? (right now it looks like it's 2 per second, perhaps a 10-per second burst would be allay developers concerns here, while still enforcing a 120 per-minute rate).

 

Thanks for your consideration, and any help you can provide.

0 Likes