cancel
Showing results for 
Search instead for 
Did you mean: 

adding child to configurable product via REST

adding child to configurable product via REST

Hi,

I'm developing an interface between Magento Rest and our ERP system. Most calls work like a charm. Currently I'm facing an issue to associate an existing simple product to an existing configurable product via REST. Both share the same attribute set.

We are using Magento 2.1.1. Configurable product sku is KF0001, simple product sku is KF00012501. To link them, I'm calling 

 

POST https://127.0.0.1/index.php/rest/V1/configurable-products/KF0001/child

{
  "childSku": "KF00012501"
}

Result:

true

Well, it seems that everthing is ok, but it isn't. In fact, the product was'nt linked, nothing was saved, everything is unchanged.

If I link the product via backend manually and save ist, then it works as expected.

Does anybody have a hint whats going wrong here? Any tips appreciated, it is a crucial function for our integration.

Kind regards,

Matthias

Tags (2)
3 REPLIES

Re: adding child to configurable product via REST

You need to add the attributes you want to use as configurable options to the configurable product with their values as ids. I am in the process of solving this issue myself, I have successfully managed to add the options, option values and association links via the api using:

configurableProductOptionRepositoryV1

POST /V1/configurable-products/{sku}/options

&

configurableProductLinkManagementV1

POST /V1/configurable-products/{sku}/child

 

I achieved this by writing the JSON request bodies statically manually inserting the id equivalents, this was very time consuming by has pointed me in the right direction. I am now writing up a module to achieve this in 1 API call.

Good luck! Smiley Very Happy

Re: adding child to configurable product via REST

Hi,

thank you very much!

Using configurableProductOptionRepositoryV1POST /V1/configurable-products/{sku}/options

doesnt work for me yet. Would you please show me your encoded messagebody? Maybe I'm missing something...

 

If I list all options for a specific product I use:

GET  https://127.0.0.1/index.php/rest/V1/configurable-products/KF0001/options/all

Result:

[
  {
    "id": 126,
    "attribute_id": "188",
    "label": "Grammatur",
    "position": 0,
    "values": [
      {
        "value_index": 351
      },
      {
        "value_index": 352
      }
    ],
    "product_id": 135
  }
]

After that I try to add another option value index "350", which does really exists. I call:

 

POST https://127.0.0.1/index.php/rest/V1/configurable-products/KF0001/options

 

Body:

{"option":
{
  "id":126,
  "values": [
      {
        "value_index": 350
      },
      {
        "value_index": 351
      },
      {
        "value_index": 352
      }
  ]
}}

Result:

126

But nothing is changed....

 

Thank you in advance, your help is really appreciated!

 

Kind regards,

Matthias

 

Re: adding child to configurable product via REST

Hi sorry for the delay in reply your missing the attribute_id and label fields in your body.

If you set them it will set correctly 😊

Kind regards,
Dan