You'd think this would be easy as falling off a log, but I'm stumped. I have an ASP.NET 3.1 core web api (using System.Text.Json):
[HttpPost]
public async Task<ActionResult> CreateAsync(JsonElement dzc)
Which in turn calls a service:
public async Task AddItemAsync(JsonElement dzc)
{
var id = dzc.GetProperty("id").GetString(); // these are both valid
var userid = dzc.GetProperty("userid").GetString();
await this._container.CreateItemAsync<JsonElement>(dzc, new PartitionKey(userid));
}
This results in: Message: {"Errors":["The input content is invalid because the required properties - 'id; ' - are missing"]}
Or if I get the raw text:
public async Task AddItemAsync(JsonElement dzc)
{
var id = dzc.GetProperty("id").GetString(); // these are all valid
var userid = dzc.GetProperty("userid").GetString();
var raw = dzc.GetRawText();
await this._container.CreateItemAsync<string>(raw, new PartitionKey(userid));
}
and raw is:
{
"id": "foozy",
"userid": "foozy",
"name": "Jayb",
"fc": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"capacity": "10",
},
"geometry": {
"type": "Point",
"coordinates": [
-71.073283,
42.417500
]
}
}
]
}
}
This results in: Message: {"Errors":["One of the specified inputs is invalid"]}
All I'm really trying to do is shovel some Json directly from an API into CosmosDB without using C# classes. What is the magic incantation?