I've created a hierarchy of classes to store all my JSON data. Here's a snippet:
public class Product { public string body_html { get; set; } public string created_at { get; set; } public string handle { get; set; } public int id { get; set; } public string product_type { get; set; } public string published_at { get; set; } public string published_scope { get; set; } public object template_suffix { get; set; } public string title { get; set; } public string updated_at { get; set; } public string vendor { get; set; } public string tags { get; set; } public List<Variant> variants { get; set; } public List<Option> options { get; set; } public List<Image> images { get; set; } public Image2 image { get; set; } } public class RootObject { public List<Product> products { get; set; } }
I then programmatically update all the data in the Products. My goal is to upload the new product info back into Shopify doing something like this:
object json = JsonConvert.SerializeObject(prod, Formatting.Indented); dynamic createProductResponse = client.Put("/admin/products/123456.json", json);
This is giving me the error (422) Unprocessable Entity.
I've looked through documentations such as this one: http://james.newtonking.com/projects/json/help/index.html?topic=html/SerializingJSON.htm#
I did a test and was able to update my products by passing a single JObject that looked something like this:
JObject obj = new JObject { {"product", new JObject{ {"title", "Product Name"}, {"product_type", "Men"}, {"id", "150056881"}, {"published_at", new DateTime(DateTime.UtcNow.Ticks, DateTimeKind.Utc)}, {"vendor", "Vendor Name"}, {"variants", new JArray{ new JObject { {"barcode", null}, {"compare_at_price", "100.00"}, { "created_at", "2013-08-04T10:43:20-07:00"}, { "fulfillment_service", "manual"}, { "grams", "100"}, { "id", "343061321"}, { "inventory_management", "shopify"}, { "inventory_policy", "deny"}, { "option1", "DARK BROWN"}, { "option2", "7"}, { "option3", null}, { "position", 1}, { "price", "75.00"}, { "product_id", "150056881"}, { "requires_shipping", true}, {"title", "DARK BROWN / 7"}, {"sku", "SKU12345"}, {"taxable", true}, { "updated_at", "2013-08-04T10:43:20-07:00"}, { "inventory_quantity", 123} } }} } } };
Thanks for any help you can offer!