zinc
May 21, 2019, 2:00am
1
Hi, can you please explain how to partially update content using the .net client library?
var accessory = new AccessoryData()
{
Name= objAccessoryImport.Name,
Price = objAccessoryImport.Price,
};
var response = await accessoryClient.PatchAsync(accessory, XXX);
What do I need to put in the XXX in the line above?
zinc
May 21, 2019, 10:57pm
4
Not yet. I did see that documentation, but I’m not sure what a TPatch is.
Sorry, for the late response. TPatch is object of a class that represents your values you want to update. E.g. if you have three fields firstName, age and country and you only want to update country the squidex API expects the following JSON
{
"age": {
"iv": 99
}
}
You have several options to implement that
Option 1: Create a custom update class
This approach works only with the custom JsonConverter that creates the nested object: https://github.com/Squidex/squidex-samples/blob/master/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/InvariantConverter.cs
public class AgeUpdate
{
[JsonConverter(typeof(InvariantConverter))]
public int Age { get; set; }
}
var update new AgeUpdate { Age = 99 };
Option 2: Create Json manually with JSON.NET
var update =
new JObject(
new JsonProperty("age", new JObject(
new JsonProperty("iv", 99))); <-- The age
Option 3: Create an anonymous object
var update = new {
age = new {
iv = 123
}
}
Option 4: Use dictionaries
var update = new Dictionary<string, object> {
["age"] = new Dictionary<string, int> {
["iv"] = 99
}
}
As long as it can be serialized to the correct json you can choose whatever you want.
My recommendations is to use #1 or #3 .
2 Likes
zinc
May 27, 2019, 3:16am
6
Awesome, thanks for the various solutions! This is exactly what I was after.