Create Product With Inventory Levels?

Solved
Highlighted
Tourist
9 1 0

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

0 Likes

Success.

Shopify Staff
Shopify Staff
1113 77 153

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
      }
    ]
  }
}
1 Like
Tourist
9 1 0
Thank you!! I appreciate your help.
0 Likes
Tourist
6 0 0

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

0 Likes
Tourist
9 1 0

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