I am working on implementing an API client in C#. The API I am working on is Close.IO.
They allow updating single fields on an object, ex) updating lead.description
https://developer.close.io/#leads-update-an-existing-lead
Request Body
{
"description": "Best show ever canceled. Sad."
}
My question, how would I create a new Lead object in c#, update the "description" property and then only send the updated description property as part of the request body?
public class Lead{
public int id {get;set;}
public string description {get;set;}
public string notes {get;set;}
}
var lead = new Lead(){
id = 1,
description = "Best show ever canceled. Sad."
}
var body = JsonConvert.SerializeObject(lead);
client.Update<Lead>(body);
In the example above, the lead with id 1 would get updated, and the description would get set, and the "notes" property would get cleared out.
Request Body
{
"id":1,
"description": "Best show ever canceled. Sad.",
"notes" : ""
}
I would only want the "description" field to get updated, and the notes field to go untouched. I'm looking for a clean way to use my typed object and serialize that into the request body and only update dirty properties.