Yes, sorry about not being clear. I would like to see how others are parsing the json to retrieve the @odata.etag token because you can't create a C# object class property with special characters, so I assume there is some manual parsing instead of using the automatic mapping. I have generic Http method functions so that I can reuse them to make the BC API calls. One of them is the Get:
private async Task<JObject> GetAsync(string url)
{
try
{
var response = await _client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsStringAsync();
var jobj = JObject.Parse(data);
return jobj;
}
catch (Exception ex)
{
throw ex;
}
}
I then call that method from a specific GetVendors function:
public async Task<Vendor> GetVendorByName(string name)
{
Vendor vendor = null;
try
{
var url = $"{_client.BaseAddress}/companies({CompanyId})/vendors?$filter=displayName eq '{CleanFilter(name)}'";
var jobj = await GetAsync(url); // since it was filtered, an array of vendors are returned (even though it's just 1 in the array)
var token = jobj.SelectToken("value");
if (token != null)
{
var vendors = token.ToObject<List<Vendor>>(); // automatically maps the json (using the standard serializer) to a list of Vendor. I would like to serialize the etag here somehow
vendor = vendors.FirstOrDefault();
}
}
catch (Exception ex)
{
throw ex;
}
return vendor;
}
Now, when I get a vendor by Id, the API returns a single object with the etag easily available, but not easily serialized from the json using the standard serlializer:
public async Task<Vendor> GetVendor(Guid id)
{
Vendor vendor = null;
try
{
var url = $"{_client.BaseAddress}/companies({CompanyId})/vendors({id})";
var jobj = await GetAsync(url);
var etag = jobj.Value<string>("@odata.etag");
vendor = jobj.ToObject<Vendor>();
vendor.ETag = etag;
}
catch (Exception ex)
{
throw ex;
}
return vendor;
}
Not sure if that's clear or not, but I'm trying to automatically serialize the json into a Vendor class and include the e-tag but I do not know how.