/// <summary> /// Deletes several products from the specified account, using custombatch. /// </summary> private void DeleteProductCustombatch(ulong merchantId, List <String> productList) { Console.WriteLine("================================================================="); Console.WriteLine("Deleting products using custombatch"); Console.WriteLine("================================================================="); ProductsCustomBatchRequest batchRequest = new ProductsCustomBatchRequest(); batchRequest.Entries = new List <ProductsCustomBatchRequestEntry>(); for (int i = 0; i < productList.Count; i++) { ProductsCustomBatchRequestEntry entry = new ProductsCustomBatchRequestEntry(); entry.BatchId = i; entry.MerchantId = merchantId; entry.Method = "delete"; entry.ProductId = productList[i]; // Use the full product ID here, not the OfferId batchRequest.Entries.Add(entry); } ProductsCustomBatchResponse response = service.Products.Custombatch(batchRequest).Execute(); if (response.Kind == "content#productsCustomBatchResponse") { for (int i = 0; i < response.Entries.Count; i++) { Errors errors = response.Entries[i].Errors; if (errors != null) { for (int j = 0; j < errors.ErrorsValue.Count; j++) { Console.WriteLine(errors.ErrorsValue[j].ToString()); } } else { Console.WriteLine("Product deleted, batchId {0}", response.Entries[i].BatchId); } } } else { Console.WriteLine( "There was an error. Response: {0}", response); } }
/// <summary> /// Inserts several products to the specified account, using custombatch. /// </summary> /// <returns>The list of product IDs, which can be used to get or delete them.</returns> private List <String> InsertProductCustombatch(ulong merchantId, string websiteUrl) { Console.WriteLine("================================================================="); Console.WriteLine("Inserting products using custombatch"); Console.WriteLine("================================================================="); ProductsCustomBatchRequest batchRequest = new ProductsCustomBatchRequest(); batchRequest.Entries = new List <ProductsCustomBatchRequestEntry>(); for (int i = 0; i < 3; i++) { ProductsCustomBatchRequestEntry entry = new ProductsCustomBatchRequestEntry(); entry.BatchId = i; entry.MerchantId = merchantId; entry.Method = "insert"; entry.Product = GenerateProduct(websiteUrl); batchRequest.Entries.Add(entry); } ProductsCustomBatchResponse response = service.Products.Custombatch(batchRequest).Execute(); List <String> productsInserted = new List <String>(); if (response.Kind == "content#productsCustomBatchResponse") { for (int i = 0; i < response.Entries.Count; i++) { Product product = response.Entries[i].Product; productsInserted.Add(product.Id); Console.WriteLine( "Product inserted with ID \"{0}\" and title \"{1}\".", product.OfferId, product.Title); shoppingUtil.PrintWarnings(product.Warnings); } } else { Console.WriteLine( "There was an error. Response: {0}", response.ToString()); } return(productsInserted); }