How to create a Product Set via API?

janvogtjanvogt Member Posts: 2
I can't get https://developers.lightspeedhq.com/ecom/endpoints/product/#post-create-a-product to work. It always creates a product with one default variant. I would expect one variant per combination of option values in the given set.
The set has been created beforehand via https://developers.lightspeedhq.com/ecom/endpoints/set/#post-create-a-set

One interesting observation is that this created set can't be used to add to a product. It says that it needs at least one option with at least one value associated, despite displaying all options and values as sent in the request. After adding one more value manually, I could associate this set with a product (both ways: create a new one or add to an existing one) and variants vor all(!) values are created. But trying to use this - now working - set to create a new Product via API still only gives me one default variant. This all seems really buggy :(

I was counting on being able to use the API for a large Product import. All with mutidimensional variants, thus CSV import is not an option. I am looking forward to any example of (a) working request(s) to create a Product set with multiple options programmatically. I would appreciate examples showing the necessary JSON payload and respective endpoints, since I'm not using the PHP client.

Answers

  • maurisourcemaurisource Partner Posts: 34 partner

    I am looking forward to any example of (a) working request(s) to create a Product set with multiple options programmatically

    The example provided by the API isn't a valid example for you?

    “options”: [{“values”: [{“sortOrder”: 1,
    “id”: 168,
    “name”: “Zwart”},
    {“sortOrder”: 2,
    “id”: 169,
    “name”: “Wit”}],
    “sortOrder”: 1,
    “id”: 76,
    “name”: “Kleur”}
    
  • ACGMACGM Member Posts: 6

    Hi Maurisource ,


    Where are the id's coming from?

    “options”: [{“values”: [{“sortOrder”: 1,
    “id”: 168,
    “name”: “Zwart”},
    {“sortOrder”: 2,
    “id”: 169,
    “name”: “Wit”}],
    “sortOrder”: 1,
    “id”: 76,
    “name”: “Kleur”}
    


  • ACGMACGM Member Posts: 6

    Hi Maurisource,


    I am using the eCom API and want to add sizes and colors and prices in a product group.

    Do you have example code how to do that.

    In addition, I cannot find any information on how to add a variant to a category or subgroup?

    Can anyone explain this to me as I don't find this anywhere in the documentation.

    Shopify does provide a good explanation, why can't Lightspeed do that too?

    I also asked myself, how should I get those IDs?

    I cannot get that id from Lightspeed.


    “Options”: [{“values”: [{“sortOrder”: 1,

    “Id”: 168, <------------------------------ where does this id come from?

    “Name”: “Black”},

    {“SortOrder”: 2,

    “Id”: 169,

    “Name”: “White”}],

    "SortOrder": 1,

    “Id”: 76,

    “Name”: “Color”}


    Hope you can give me an answer, because we are stuck.


    Kind regars,


    ACGM

  • maurisourcemaurisource Partner Posts: 34 partner
    edited March 31

    @ACGM The eCom API is quite different than the Lightspeed Retail one you quoted. But the logic should remain the same. The eCom API should provide you with API response requests sample for the endpoint you're trying to get data from.

    Look here:


    you'll find the property "set" which returns the Product option set (if available). The returned options will looks like this:


    {“set”: {“id”: 2785,
    “createdAt”: “2019-05-28T15:32:12+00:00”,
    “updatedAt”: “2019-05-28T15:42:59+00:00”,
    “options”: [{“id”: 4626,
    “sortOrder”: 1,
    “name”: “Size”,
    “values”: [{ “id”: 14045,
    “sortOrder”: 1,
    “name”: “S”},
    {“id”: 14046,
    “sortOrder”: 2,
    “name”: “M”},
    {“id”: 14047,
    “sortOrder”: 3,
    “name”: “L”}]}]}}
    
    Manesh Sonah < Magento Developer | Laravel Developer />
    https://maurisource.com / [email protected]endesk.com
    Magento 1 integration | Magento 2 integration | Custom integrations? Hire me


  • ACGMACGM Member Posts: 6

    Hi Manesh,


    With all due respect but you are not answering my question(s).

    I asked for sample code how to add colors, sizes and prices to a product (variant). There is no documentation on how to do that.

    I hope you have something for me.

    Kind regards,

    André

  • maurisourcemaurisource Partner Posts: 34 partner

    @ACGM Sorry I don't work for you. This is a community Channel, if you want some free code you should come by with your own first. If you don't know how to code, hire a developer accordingly

  • Ali_MasoumieAli_Masoumie Moderator, Lightspeed Staff Posts: 63 moderator

    You can create product sets with colors and sizes and assign it to a product:

    {
      "product": {
        "set": {"id": productset_id here}
      }
    }
    

    This will automatically create variants of that product for each combination of options. You can then update each variant:

    {
      "variant": {
        "priceExcl": 100,
        "priceIncl": 121
      }
    }
    

    If you do not want to use product sets, you can manually create new variants.


    Links to our documentations:

    Product sets: https://developers.lightspeedhq.com/ecom/endpoints/set/#post-create-a-set

    Products: https://developers.lightspeedhq.com/ecom/endpoints/product/#put-update-a-product

    Variants: https://developers.lightspeedhq.com/ecom/endpoints/variant/

    Hope this helps.

  • ACGMACGM Member Posts: 6

    Hi Ali_Masoumie,

    Thanks for the response.


    Currently we faces the problem that we encounter for example 3 times the variant with the size 104 under a product because we do not know how to further split this variant into colors and prices or subgroups.

    The documentation is not very clear on this.


    We have already created the variants (5000) and the website is also live.

    So we have to update the variants.

    For example, we have a product "T-shirt".

    We have the variant size 104, in the color yellow

    and a variant with size 104, in the color red.

    We want to divide both variants into "Girls" and "Boys".


    How do you do this using the eCom API?


    Kind regards,


    André

  • Ali_MasoumieAli_Masoumie Moderator, Lightspeed Staff Posts: 63 moderator

    Hi André,

    It would be best to do this on Category level and not on variant level.

Sign In or Register to comment.