skip to Main Content

According to the Shopify documentation you can post a product variant like so:

  "variant" => [
    "title" => "Guzman",
    "price" => "44.90",
    "sku" => "160011",
    "position" => 1,
    "inventory_policy" => "continue",
    "compare_at_price" => null,
    "fulfillment_service" => "manual",
    "inventory_management" => "shopify",
    "option1" => "Option1",
  ]

The above example is using Guzzle. The above code posts to the product I’m referencing. The problem is I can’t find how to change or set the option title. In example the default one is title:

enter image description here

On the shopify admin this would be set by “Edit Options” but I don’t find anywhere in the API documentation on how this could be set.

2

Answers


  1. Chosen as BEST ANSWER

    The solution for this was that the variant title is not actually in variant. It is in product api.

    The correct way to modify the title would be like this:

    $response = $shop->api()->rest('PUT', '/admin/products/{productId}.json' ,[
      "product" => [
        "option" => [
        "name" => "Size"
      ]
      ]
    ]);
    

    Further documentation here: https://help.shopify.com/en/api/reference/products/product

    What threw me off was that I was in the variant api assuming variant would be where the title was.


  2. As far as I know, title is based on your option.
    if option1 is red and option2 is large, title would be red / large.

    If you want to change Default Title, pass option value in title field as follow in variants array.

    PUT /admin/products/121212121212.json
    
    {
        "product": {
            "id": 121212121212,
            "variants": [
                {
                    "title": "Guzman",
                    "price": 44.90,
                    "sku" :"160011",
                    "position": 1,
                    "inventory_policy": "continue",
                    "compare_at_price": null,
                    "fulfillment_service": "manual",
                    "inventory_management": "shopify",
                    "option1": "Guzman"
                }
            ]
        }
    }
    

    You can try it in postman and let me know if this worked for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search