Home › Forums › General Issues › Importing Data into ACF Fields using API Error Received › Reply To: Importing Data into ACF Fields using API Error Received
// products_id = "621757000000383001";
product = zoho.crm.getRecordById("Products",products_id);
productData = Map();
productData.put("name",product.get("Product_Name"));
productData.put("regular_price",product.get("Unit_Price"));
woocommerceProductId = product.get("Woocommerce_Product_ID");
if(woocommerceProductId != null)
{
response = invokeurl
[
url :"https://mywoocommercetozoho.asteamwork.com/wp-json/wc/v3/products/" + woocommerceProductId
type :Put
parameters:productData
connection:"as"
];
info response;
if(response.get("id") != null)
{
woocommercedata = Map();
woocommercedata.put("Woocommerce_Product_ID",response.get("id"));
update = zoho.crm.updateRecord("Products",products_id,woocommercedata);
info update;
meta_data = response.get("meta_data");
if(meta_data == null)
{
meta_data = List();
}
// Check if "zoho_product_id" key exists in meta_data
zoho_product_id_exists = false;
for each meta in meta_data
{
if(meta.get("key") == "zoho_product_id")
{
meta.put("value",toString(products_id));
zoho_product_id_exists = true;
}
}
// If "zoho_product_id" key doesn't exist, add it to meta_data
if(!zoho_product_id_exists)
{
new_meta = Map();
new_meta.put("key","zoho_product_id");
new_meta.put("value",toString(products_id));
meta_data.add(new_meta);
}
productData1 = Map();
productData1.put("meta_data",meta_data);
sample_file = invokeurl
[
url :"https://mywoocommercetozoho.asteamwork.com/wp-json/wc/v3/products/" + response.get("id")
type :PUT
parameters:productData1.toString()
connection:"as"
content-type:"application/json"
];
info "Sample file:" + sample_file;
}
else
{
info "WooCommerce product update failed.";
}
}
else
{
response = invokeurl
[
url :"https://mywoocommercetozoho.asteamwork.com/wp-json/wc/v3/products"
type :Post
parameters:productData
connection:"as"
];
info response;
if(response.get("id") != null)
{
woocommercedata = Map();
woocommercedata.put("Woocommerce_Product_ID",response.get("id"));
update = zoho.crm.updateRecord("Products",products_id,woocommercedata);
info update;
meta_data = response.get("meta_data");
if(meta_data == null)
{
meta_data = List();
}
// Check if "zoho_product_id" key exists in meta_data
zoho_product_id_exists = false;
for each meta in meta_data
{
if(meta.get("key") == "zoho_product_id")
{
meta.put("value",toString(products_id));
zoho_product_id_exists = true;
}
}
// If "zoho_product_id" key doesn't exist, add it to meta_data
if(!zoho_product_id_exists)
{
new_meta = Map();
new_meta.put("key","zoho_product_id");
new_meta.put("value",toString(products_id));
meta_data.add(new_meta);
}
productData1 = Map();
productData1.put("meta_data",meta_data);
sample_file = invokeurl
[
url :"https://mywoocommercetozoho.asteamwork.com/wp-json/wc/v3/products/" + response.get("id")
type :PUT
parameters:productData1.toString()
connection:"as"
content-type:"application/json"
];
info "Sample file:" + sample_file;
}
else
{
info "WooCommerce product creation failed.";
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.