Support

Account

Home Forums General Issues Importing Data into ACF Fields using API Error Received

Helping

Importing Data into ACF Fields using API Error Received

  • Hello to all forum members, I am hoping you can please help me, I have only recently started to use ACF to add content to my woocommerce single product template which works well when I import new products using csv import, I am currently using the free version (but obviously planning to upgrade!).

    We are now trying to add new products by automation using api, when importing we get the system fields populated but none of the ACF fields data is added and we receive an error?

    This is the error we receive:

    {“code”:”rest_invalid_param”,”message”:”Invalid parameter(s): meta_data”,”data”:{“status”:400,”params”:{“meta_data”:”meta_data[0] is not of type object.”},”details”:{“meta_data”:{“code”:”rest_invalid_type”,”message”:”meta_data[0] is not of type object.”,”data”:{“param”:”meta_data[0]”}}}}}

    If we create products without meta_data fields (ACF Fields), then It seems to perfectly create a new product.

    I have also added here an attachment, I attach the error screenshot.

    Many thanks for any help or guidance, we look forward to hearing from you.

  • 
    // 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 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.