Creation of Products with Multiple Options

cookseytalbott
New Member
3 0 0

I have been trying to create products that have 2 options, Size and Presentation, with a number of variants based on the option combinations.

I can create and update the product data, variant data tables and images successfully using their respective API’s. 

I am not finding a pat answer to the creation of options in the API docs and forums.  

I also find that if I update a product's option it does not change the field values. The response has a 200 OK and the data which has not been altered. 

Can you direct me to some information on how to create a product with multiple options?

Here is some detail...
--------------------------------------------------------------------------------------------------------
If I create a product:

Endpoint: /admin/products.json POST

{
    "Content-type": "application\/json",
    "client_id": "c0c214c7a47bb89ccd4a5b9425d28518",
    "client_secret": "CLIENT_SECRET",
    "code": "C8B67F9D-3FCB-4280-97FB-D1C9EA5EA469",
    "product": {
        "title": "Test Product",
        "body_html": "Copy Here",
        "vendor": "New Vendor",
        "product_type": "Product Type",
        "tags": "tag1, tag2, tag3"
    }
}

I get back a 201 CREATED and the product is successfully created.

--------------------------------------------------------------------------------------------------------

If I add a variant that calls for 2 options:

Endpoint: /admin/products/$productID/variants.json POST

{
    "Content-type": "application\/json",
    "client_id": "c0c214c7a47bb89ccd4a5b9425d28518",
    "client_secret": "CLIENT_SECRET",
    "code": "C8B67F9D-3FCB-4280-97FB-D1C9EA5EA469",
    "variant": {
        "option1": "8x10",
        "option2": "BOX",
        "price": "10.02",
        "sku": "667"
    }
}

--------------------------------------------------------------------------------------------------------

I get back an error 422 UNPROCESSABLE because only 1 option exists. I need to add another option.

array (
  'headers' => 
  array (
    'status' => 'HTTP/1.1 422 Unprocessable Entity
',
    'Server' => 'nginx',
    'Date' => 'Fri, 19 Aug 2016 04',
    'Content-Type' => 'application/json; charset=utf-8',
    'Transfer-Encoding' => 'chunked',
    'Connection' => 'keep-alive',
    'X-Frame-Options' => 'DENY',
    'X-ShopId' => '12574961',
    'X-ShardId' => '2',
    'X-Shopify-Shop-Api-Call-Limit' => '1/40',
    'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' => '1/40',
    'X-Stats-UserId' => '0',
    'X-Stats-ApiClientId' => '1331177',
    'X-Stats-ApiPermissionId' => '23028690',
    'X-XSS-Protection' => '1; mode=block; report=/xss-report/c2859570-f814-4fd1-879f-1139339d45f7?source%5Baction%5D=create&source%5Bcontroller%5D=admin%2Fproduct_variants&source%5Bsection%5D=admin',
    'X-Request-Id' => 'c2859570-f814-4fd1-879f-1139339d45f7',
    'X-Dc' => 'ash',
  ),
  'response' => '{"errors":{"base":["2 option values given but 1 options exist"]}}',
)

--------------------------------------------------------------------------------------------------------

If I create a new variant that only refers to option1

Endpoint: /admin/products/$productID/variants.json POST

{
    "Content-type": "application\/json",
    "client_id": "c0c214c7a47bb89ccd4a5b9425d28518",
    "client_secret": "CLIENT_SECRET",
    "code": "C8B67F9D-3FCB-4280-97FB-D1C9EA5EA469",
    "variant": {
        "option1": "8x10",
        "price": "10.02",
        "sku": "667"
    }
}

--------------------------------------------------------------------------------------------------------

I get a 201 CREATED and the product now has 2 variants. The values array sub[1] in option1 has been automatically fixed up with the value “8x10”.

[
    {
        "id": 8066111875,
        "title": "Test Product",
        "body_html": "Copy Here",
        "vendor": "New Vendor",
        "product_type": "Product Type",
        "created_at": "2016-08-18T21:08:38-07:00",
        "handle": "test-product-11",
        "updated_at": "2016-08-18T21:08:39-07:00",
        "published_at": "2016-08-18T21:08:38-07:00",
        "template_suffix": null,
        "published_scope": "global",
        "tags": "tag1, tag2, tag3",
        "variants": [
            {
                "id": 26079398659,
                "product_id": 8066111875,
                "title": "Default Title",
                "price": "0.00",
                "sku": "",
                "position": 1,
                "grams": 0,
                "inventory_policy": "deny",
                "compare_at_price": null,
                "fulfillment_service": "manual",
                "inventory_management": null,
                "option1": "Default Title",
                "option2": null,
                "option3": null,
                "created_at": "2016-08-18T21:08:38-07:00",
                "updated_at": "2016-08-18T21:08:38-07:00",
                "taxable": true,
                "barcode": null,
                "image_id": null,
                "inventory_quantity": 1,
                "weight": 0,
                "weight_unit": "lb",
                "old_inventory_quantity": 1,
                "requires_shipping": true
            },
            {
                "id": 26079398723,
                "product_id": 8066111875,
                "title": "8x10",
                "price": "10.02",
                "sku": "667",
                "position": 2,
                "grams": 0,
                "inventory_policy": "deny",
                "compare_at_price": null,
                "fulfillment_service": "manual",
                "inventory_management": null,
                "option1": "8x10",
                "option2": null,
                "option3": null,
                "created_at": "2016-08-18T21:08:39-07:00",
                "updated_at": "2016-08-18T21:08:39-07:00",
                "taxable": true,
                "barcode": null,
                "image_id": null,
                "inventory_quantity": 1,
                "weight": 0,
                "weight_unit": "lb",
                "old_inventory_quantity": 1,
                "requires_shipping": true
            }
        ],
        "options": [
            {
                "id": 9676121795,
                "product_id": 8066111875,
                "name": "Title",
                "position": 1,
                "values": [
                    "Default Title",
                    "8x10"
                ]
            }
        ],
        "images": [],
        "image": null
    }
]

--------------------------------------------------------------------------------------------------------

I try to change the title of option1, the default option, get a 200 OK but the title does not change.

endpoint: /admin/products/8066111875.json PUT

{
    "Content-type": "application\/json",
    "client_id": "c0c214c7a47bb89ccd4a5b9425d28518",
    "client_secret": "CLIENT_SECRET",
    "code": "C8B67F9D-3FCB-4280-97FB-D1C9EA5EA469",
    "product": {
        "id": 8066111875,
        "options": [
            {
                "id": 9676121795,
                "product_id": 8066111875,
                "name": "Size"
            }
        ]
    }
}

--------------------------------------------------------------------------------------------------------

If I update the product to have a new option:

endpoint: /admin/products/8066111875.json PUT

{
    "Content-type": "application\/json",
    "client_id": "c0c214c7a47bb89ccd4a5b9425d28518",
    "client_secret": "CLIENT_SECRET",
    "code": "C8B67F9D-3FCB-4280-97FB-D1C9EA5EA469",
    "product": {
        "id": 8066111875,
        "options": [
            {
                "product_id": 8066111875,
                "name": "Presentation",
                "position": 2
            }
        ]
    }
}

I get back a 200 OK but the data does not change.

{
    "id": 8066111875,
    "title": "Test Product",
    "body_html": "Copy Here",
    "vendor": "New Vendor",
    "product_type": "Product Type",
    "created_at": "2016-08-18T21:08:38-07:00",
    "handle": "test-product-11",
    "updated_at": "2016-08-18T21:08:39-07:00",
    "published_at": "2016-08-18T21:08:38-07:00",
    "template_suffix": null,
    "published_scope": "global",
    "tags": "tag1, tag2, tag3",
    "variants": [
        {
            "id": 26079398659,
            "product_id": 8066111875,
            "title": "Default Title",
            "price": "0.00",
            "sku": "",
            "position": 1,
            "grams": 0,
            "inventory_policy": "deny",
            "compare_at_price": null,
            "fulfillment_service": "manual",
            "inventory_management": null,
            "option1": "Default Title",
            "option2": null,
            "option3": null,
            "created_at": "2016-08-18T21:08:38-07:00",
            "updated_at": "2016-08-18T21:08:38-07:00",
            "taxable": true,
            "barcode": null,
            "image_id": null,
            "inventory_quantity": 1,
            "weight": 0,
            "weight_unit": "lb",
            "old_inventory_quantity": 1,
            "requires_shipping": true
        },
        {
            "id": 26079398723,
            "product_id": 8066111875,
            "title": "8x10",
            "price": "10.02",
            "sku": "667",
            "position": 2,
            "grams": 0,
            "inventory_policy": "deny",
            "compare_at_price": null,
            "fulfillment_service": "manual",
            "inventory_management": null,
            "option1": "8x10",
            "option2": null,
            "option3": null,
            "created_at": "2016-08-18T21:08:39-07:00",
            "updated_at": "2016-08-18T21:08:39-07:00",
            "taxable": true,
            "barcode": null,
            "image_id": null,
            "inventory_quantity": 1,
            "weight": 0,
            "weight_unit": "lb",
            "old_inventory_quantity": 1,
            "requires_shipping": true
        }
    ],
    "options": [
        {
            "id": 9676121795,
            "product_id": 8066111875,
            "name": "Title",
            "position": 1,
            "values": [
                "Default Title",
                "8x10"
            ]
        }
    ],
    "images": [],
    "image": null
}

After several days of going back and forth over this problem I decided that asking for help might produce a result...

My questions are specifically:

1) Is it possible to create a complete product with multiple options using the API?
2) How do you create a new option?
3) How do you perform an update on an existing option?
4) What is the necesary order of operations to create a product with multiple options.
5) Is it possible to update the default option?

Thanks!


Ralph Cooksey-Talbott
cooksey ~a-t~ rollinghillssoftware.com
ShopID: reprint-mint
APIKey: c0c214c7a47bb89ccd4a5b9425d28518
TestProductID: 8066111875
Product with correct options and variants made with test store: 7805912259


 

0 Likes
Garrett_Boone
Shopify Partner
2 0 0

Hey Ralph, 

I was having the same issue and havent been able to test yet, but messing around with the Shopify UI I found that you have to create a new 'option' before being able to use it.  I believe this lives on the product, not the variant of the product. So you need to tell that product that it can have 3 options and set their default values. 

 

look at the options attr https://help.shopify.com/api/reference/product

UI reference go to  product > variants > edit options > add another option

Hope this helps. 

0 Likes
Pogodan
Shopify Expert
76 0 11

Ralph,

Check out the structure in the API docs:

    "options": [
      {
        "id": 594680422,
        "product_id": 632910392,
        "name": "Color",
        "position": 1,
        "values": [
          "Pink",
          "Red",
          "Green",
          "Black"
        ]
      }
    ],

You should be able to do a POST/PUT to set a product to the options and positions you want, and (the the same or a subsequent API call) set the variants with the option1/option2/option3 values matching the `position` for the product options.

Pogodan | https://experts.shopify.com/pogodan-dev
0 Likes
cookseytalbott
New Member
3 0 0

Thanks for the responses guys I really appreciate the helpful suggestions! 

Here are some of the steps that I have gone through towards creating additional options using the Product Update (PUT) API. 

Below this bit is an example of the results from the Product Create (POST) API.

1) I create a product via the API, the operation is successful.

This structure is returned:

    {
        "id": 8059972099,
        "title": "Test Product",
        "body_html": "Copy Here",
        "vendor": "New Vendor",
        "product_type": "Product Type",
        "created_at": "2016-08-18T13:54:16-07:00",
        "handle": "test-product-2",
        "updated_at": "2016-08-25T15:36:09-07:00",
        "published_at": "2016-08-18T13:54:16-07:00",
        "template_suffix": null,
        "published_scope": "global",
        "tags": "MOD, tag1, tag2, tag3",
        "variants": [
            {
                "id": 26058963139,
                "product_id": 8059972099,
                "title": "Default Title",
                "price": "0.00",
                "sku": "",
                "position": 1,
                "grams": 0,
                "inventory_policy": "deny",
                "compare_at_price": null,
                "fulfillment_service": "manual",
                "inventory_management": null,
                "option1": "Default Title",
                "option2": null,
                "option3": null,
                "created_at": "2016-08-18T13:54:16-07:00",
                "updated_at": "2016-08-18T13:54:16-07:00",
                "taxable": true,
                "barcode": null,
                "image_id": null,
                "inventory_quantity": 1,
                "weight": 0,
                "weight_unit": "lb",
                "old_inventory_quantity": 1,
                "requires_shipping": true
            }
        ],
        "options": [
            {
                "id": 9668967107,
                "product_id": 8059972099,
                "name": "Title",
                "position": 1,
                "values": [
                    "Default Title"
                ]
            }
        ],
        "images": [],
        "image": null
    }

-------------------------------------------------------------------------------------------------
2) I perform an update operation and alter some of the mutable fields to see that I got an update.

In this case I get an update on the Product's top level fields title, body_html, vendor, product_type and tags but NOT on the options. 

HTTP Status:: HTTP/1.1 200 OK 

Here is my request:

{
    "id": "8059972099",
    "title": "Test Product MOD",
    "body_html": "Copy Here MOD",
    "vendor": "New Vendor MOD",
    "product_type": "Product Type MOD",
    "tags": "tag1, tag2, tag3, MOD",
    "options": [
        {
            "name": "Size",
            "values": [
                "8x10"
            ]
        },
        {
            "name": "Presentation",
            "values": [
                "Box"
            ]
        }
    ]
}

Here is the response:

{
    "id": 8059972099,
    "title": "Test Product MOD",
    "body_html": "Copy Here MOD",
    "vendor": "New Vendor MOD",
    "product_type": "Product Type MOD",
    "created_at": "2016-08-18T13:54:16-07:00",
    "handle": "test-product-2",
    "updated_at": "2016-08-25T15:36:09-07:00",
    "published_at": "2016-08-18T13:54:16-07:00",
    "template_suffix": null,
    "published_scope": "global",
    "tags": "MOD, tag1, tag2, tag3",
    "variants": [
        {
            "id": 26058963139,
            "product_id": 8059972099,
            "title": "Default Title",
            "price": "0.00",
            "sku": "",
            "position": 1,
            "grams": 0,
            "inventory_policy": "deny",
            "compare_at_price": null,
            "fulfillment_service": "manual",
            "inventory_management": null,
            "option1": "Default Title",
            "option2": null,
            "option3": null,
            "created_at": "2016-08-18T13:54:16-07:00",
            "updated_at": "2016-08-18T13:54:16-07:00",
            "taxable": true,
            "barcode": null,
            "image_id": null,
            "inventory_quantity": 1,
            "weight": 0,
            "weight_unit": "lb",
            "old_inventory_quantity": 1,
            "requires_shipping": true
        }
    ],
    "options": [
        {
            "id": 9668967107,
            "product_id": 8059972099,
            "name": "Title",
            "position": 1,
            "values": [
                "Default Title"
            ]
        }
    ],
    "images": [],
    "image": null
}

-------------------------------------------------------------------------------------------------
Maybe I am missing members in the Option.
 
I will add position and request an update...

Once again the Product gets updated but the Option request fails silently.

HTTP/1.1 200 OK 

Request:

{
    "id": "8059972099",
    "title": "Test Product MOD2",
    "body_html": "Copy Here MOD2",
    "vendor": "New Vendor MOD2",
    "product_type": "Product Type MOD2",
    "tags": "tag1, tag2, tag3, MOD2",
    "options": [
        {
            "name": "Size",
            "position": "2",
            "values": [
                "8x10"
            ]
        },
        {
            "name": "Presentation",
            "position": "3",
            "values": [
                "Box"
            ]
        }
    ]
}

Response:

    {
        "id": 8059972099,
        "title": "Test Product MOD2",
        "body_html": "Copy Here MOD2",
        "vendor": "New Vendor MOD2",
        "product_type": "Product Type MOD2",
        "created_at": "2016-08-18T13:54:16-07:00",
        "handle": "test-product-2",
        "updated_at": "2016-08-29T15:21:48-07:00",
        "published_at": "2016-08-18T13:54:16-07:00",
        "template_suffix": null,
        "published_scope": "global",
        "tags": "MOD2, tag1, tag2, tag3",
        "variants": [
            {
                "id": 26058963139,
                "product_id": 8059972099,
                "title": "Default Title",
                "price": "0.00",
                "sku": "",
                "position": 1,
                "grams": 0,
                "inventory_policy": "deny",
                "compare_at_price": null,
                "fulfillment_service": "manual",
                "inventory_management": null,
                "option1": "Default Title",
                "option2": null,
                "option3": null,
                "created_at": "2016-08-18T13:54:16-07:00",
                "updated_at": "2016-08-18T13:54:16-07:00",
                "taxable": true,
                "barcode": null,
                "image_id": null,
                "inventory_quantity": 1,
                "weight": 0,
                "weight_unit": "lb",
                "old_inventory_quantity": 1,
                "requires_shipping": true
            }
        ],
        "options": [
            {
                "id": 9668967107,
                "product_id": 8059972099,
                "name": "Title",
                "position": 1,
                "values": [
                    "Default Title"
                ]
            }
        ],
        "images": [],
        "image": null
    }


-------------------------------------------------------------------------------------------------
Create a New Product using the POST API
-------------------------------------------------------------------------------------------------

If I request a Product with two or three Options I get back the "Name can't be blank" error.

2 Options 

{
    "title": "Test Product 49",
    "body_html": "Copy Here",
    "vendor": "New Vendor",
    "product_type": "Product Type",
    "tags": "tag1, tag2, tag3",
    "options": [
        {
            "name": "Size",
            "position": "2",
            "values": [
                "8x10"
            ]
        },
        {
            "name": "Presentation",
            "position": "3",
            "values": [
                "Box"
            ]
        }
    ]
}

3 Options 

{
    "title": "Test Product 49",
    "body_html": "Copy Here",
    "vendor": "New Vendor",
    "product_type": "Product Type",
    "tags": "tag1, tag2, tag3",
    "options": [
        {
            "name": "Media",
            "position": "1",
            "values": [
                "Archival Matte"
            ]
        },
        {
            "name": "Size",
            "position": "2",
            "values": [
                "8x10"
            ]
        },
        {
            "name": "Presentation",
            "position": "3",
            "values": [
                "Box"
            ]
        }
    ]
}


Response

{
    "errors":
        {
        "options":["is invalid"],
        "name":["can\'t be blank"]
        }
}

Just to sanity check I will create a new Product with no Options...

Request:

array (
  'title' => 'Test Product 50',
  'body_html' => 'Copy Here',
  'vendor' => 'New Vendor',
  'product_type' => 'Product Type',
  'tags' => 'tag1, tag2, tag3',
)

Response:

array (
  0 => 
  array (
    'id' => 8226759875,
    'title' => 'Test Product 50',
    'body_html' => 'Copy Here',
    'vendor' => 'New Vendor',
    'product_type' => 'Product Type',
    'created_at' => '2016-08-29T15:50:55-07:00',
    'handle' => 'test-product-50',
    'updated_at' => '2016-08-29T15:50:55-07:00',
    'published_at' => '2016-08-29T15:50:54-07:00',
    'template_suffix' => NULL,
    'published_scope' => 'global',
    'tags' => 'tag1, tag2, tag3',
    'variants' => 
    array (
      0 => 
      array (
        'id' => 26878780675,
        'product_id' => 8226759875,
        'title' => 'Default Title',
        'price' => '0.00',
        'sku' => '',
        'position' => 1,
        'grams' => 0,
        'inventory_policy' => 'deny',
        'compare_at_price' => NULL,
        'fulfillment_service' => 'manual',
        'inventory_management' => NULL,
        'option1' => 'Default Title',
        'option2' => NULL,
        'option3' => NULL,
        'created_at' => '2016-08-29T15:50:55-07:00',
        'updated_at' => '2016-08-29T15:50:55-07:00',
        'taxable' => true,
        'barcode' => NULL,
        'image_id' => NULL,
        'inventory_quantity' => 1,
        'weight' => 0,
        'weight_unit' => 'lb',
        'old_inventory_quantity' => 1,
        'requires_shipping' => true,
      ),
    ),
    'options' => 
    array (
      0 => 
      array (
        'id' => 9871927235,
        'product_id' => 8226759875,
        'name' => 'Title',
        'position' => 1,
        'values' => 
        array (
          0 => 'Default Title',
        ),
      ),
    ),
    'images' => 
    array (
    ),
    'image' => NULL,
  ),
)

Let me know if either of you make some progress on this front. I am stalled on this project currently.

Thanks Again,

Ralph Cooksey-Talbott
cooksey ~A-T~ rollinghillssoftware.com
ShopID: reprint-mint
APIKey: c0c214c7a47bb89ccd4a5b9425d28518

0 Likes
Saad4
New Member
4 0 0

Hey Ralph, So have you added a product with multiple options using the API ? Or even updated/deleted options for the product ?

0 Likes
Saad4
New Member
4 0 0

Hey Ralph, So have you added a product with multiple options using the API ? Or even updated/deleted options for the product ?

0 Likes
BrianMoney
New Member
1 0 0

Has anyone had luck with this?

It would be super helpful to be able to create multiple variant options. Here's the closest I've come

{
    "product": {
        "options": [
            {
                "name""Size",
                "position"1,
                "values": [
                    "big","small"
                ]
            },
            {
                "name""Color",
                "position"2,
                "values": [
                    "blue","red"
                ]
            }
        ]
    }
}
 
It works with a single option, the second option (regardless of values) always triggers and error
code: 422 Unprocessable Entity
"You need to add option values for Color"
0 Likes