Support

Account

Forum Replies Created

  • 
    // 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.";
    	}
    }
    
Viewing 1 post (of 1 total)