cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 REST API Import and Associate Simple Product to Configurable Product

SOLVED

Magento 2 REST API Import and Associate Simple Product to Configurable Product

I'm a ColdFusion Developer who is new to Magento 2.  I'm trying to understand the process of adding simple and configurable products.  I'm utilizing the Rest APIs but the documentation is very vague.  At first I created configurable products.  That process worked fine.  I'm not trying to create simple products and associate those to the configurable products using the REST APIs but the JSON provided in the documentation is a bit confusing.

 

  • Has anyone ever utilized the REST APIs to import products from an XML file then create simple/configurable products?
  • What is the best practice for creating configurable products?  Do I create the configurable product first or the simple product?
  • How should my JSON be formatted in order to successfully associate a simple product to a configurable product?
  • Does anyone have any examples they can provide?

Thanks for any help you guys can provide.

 

Keith

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

Hi Sherrie.

 

I was able to figure it out by making a call to REST API configurableProductLinkManagementV1.  Here is the code I used in my ColdFusion function:

 

  <cfargument name="authToken" required="yes">
  <cfargument name="parentSKU" required="yes">
  <cfargument name="childSKU" required="yes">
 
  <cfset var urlAddress = "" />
  <cfset var inputJSON = "" />
 
  <cfset urlAddress = "#Application.MagentoHost#/rest/V1/configurable-products/#arguments.parentSKU#/child">
  
  <cfset inputJSON = '{"childSku": "#arguments.childSKU#"}' />
 
  <cfhttp url="#urlAddress#" method="post" result="resSimpleConfigProduct">
   <cfhttpparam type="header" name="Content-Type" value="application/json" />
   <cfhttpparam type="header" name="Authorization" value="Bearer #arguments.authToken#" />
   <cfhttpparam type="body" value='#inputJSON#' />
  </cfhttp>

 

After doing so, I then made a call to REST API configurableProductOptionRepositoryV1 to add options to the configurable product.  Here is the code I used in my ColdFusion function:

 

<cfargument name="authToken" required="yes">
  <cfargument name="sku" required="yes">
  <cfargument name="optionJSON" required="yes">
 
  <cfset var urlAddress = "" />
  
  <cfset urlAddress = "#Application.MagentoHost#/rest/V1/configurable-products/#arguments.sku#/options">
 
   <cfhttp url="#urlAddress#" method="post" result="resAddConfigOptions">
   <cfhttpparam type="header" name="Content-Type" value="application/json" />
   <cfhttpparam type="header" name="Authorization" value="Bearer #arguments.authToken#" />
   <cfhttpparam type="body" value='#arguments.optionJSON#' />
  </cfhttp>

  

Thanks for the follow-up!

View solution in original post

8 REPLIES 8

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

Hi @KCarmichael, were you able to find what you were looking for here?

--

Developer Relations, Adobe Experience Cloud
Problem solved? Click Accept as Solution!
Still stuck? Check out our documentation: https://magento.com/resources/technical

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

Hi Sherrie.

 

I was able to figure it out by making a call to REST API configurableProductLinkManagementV1.  Here is the code I used in my ColdFusion function:

 

  <cfargument name="authToken" required="yes">
  <cfargument name="parentSKU" required="yes">
  <cfargument name="childSKU" required="yes">
 
  <cfset var urlAddress = "" />
  <cfset var inputJSON = "" />
 
  <cfset urlAddress = "#Application.MagentoHost#/rest/V1/configurable-products/#arguments.parentSKU#/child">
  
  <cfset inputJSON = '{"childSku": "#arguments.childSKU#"}' />
 
  <cfhttp url="#urlAddress#" method="post" result="resSimpleConfigProduct">
   <cfhttpparam type="header" name="Content-Type" value="application/json" />
   <cfhttpparam type="header" name="Authorization" value="Bearer #arguments.authToken#" />
   <cfhttpparam type="body" value='#inputJSON#' />
  </cfhttp>

 

After doing so, I then made a call to REST API configurableProductOptionRepositoryV1 to add options to the configurable product.  Here is the code I used in my ColdFusion function:

 

<cfargument name="authToken" required="yes">
  <cfargument name="sku" required="yes">
  <cfargument name="optionJSON" required="yes">
 
  <cfset var urlAddress = "" />
  
  <cfset urlAddress = "#Application.MagentoHost#/rest/V1/configurable-products/#arguments.sku#/options">
 
   <cfhttp url="#urlAddress#" method="post" result="resAddConfigOptions">
   <cfhttpparam type="header" name="Content-Type" value="application/json" />
   <cfhttpparam type="header" name="Authorization" value="Bearer #arguments.authToken#" />
   <cfhttpparam type="body" value='#arguments.optionJSON#' />
  </cfhttp>

  

Thanks for the follow-up!

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

Glad you got it sorted @KCarmichael, thanks for reporting back with the solution! Smiley Happy

--

Developer Relations, Adobe Experience Cloud
Problem solved? Click Accept as Solution!
Still stuck? Check out our documentation: https://magento.com/resources/technical

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

Hi!

I work with Magento 2.

I don't understand respectively can not use this code, because i am not a programmer.

Can you explain it to me in a "normal lenguage"?

My question is: How can connect already existing simple products with a configurable parent product (like in it works in Magento 1) ??? I know Magento 2 is different...

 

I know how it works to create and connect NEW simples via a config. parent product. But this not my question. Is there such a function for connecting existing simples with config. parents?

 

Can you help me, please?

 

Maybe i should give this code to our programmer... perhaps he can use it?! But finally, i still can't work with Magento 2, if myself don't know how it works!

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

Hi again!

I think this code isn't the right one for me...

Because it relates to creating and connecting  NEW simple products via a configurable parent product. It seems to me that the code, which i need, doesn't exist respectively no one has an answer for me. In my opinion that is because Magento 2 isn't a ready-programmed system!!!

 

 

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

I need a programmer who can programm this code for me!

Is there anyone who can do this???

Magento 2 is so new that no one knows this answer?!

 

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product

Hey.

I'm not a programmer so I would like to know if you got an answer to your following question :
"What is the best practice for creating configurable products? Do I create the configurable product first or the simple product?"

Thank you :-)

Steven

Re: Magento 2 REST API Import and Associate Simple Product to Configurable Product