Azure CosmosDB dotnet sdk v3 ["One of the specified inputs is invalid"]

So after an hour of frustration, I finally managed to figure out why I wasn’t able to do a simple Insert in a Cosmos collection using the latest v3 dotnet sdk

For the first time in a while I was playing with the raw SDK(shameless plug - I usually use the wrapper I wrote that abstracts away a lot of the internals of dealing with the documents and SDK itself) and I was getting this weird exeption while trying to perform the most basic Insert/Upsert operation:

1
await _container.UpsertItemAsync(movie, new PartitionKey(movie.Title))

__container’s PartitionKey definition is /Title_

1
Microsoft.Azure.Cosmos.CosmosException: 'Response status code does not indicate success: 400 Substatus: 0 Reason: (Message: {"Errors":["One of the specified inputs is invalid"]}

Here’s the full definition of the object I’m trying to insert:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Movie
{
public string Id { get; set; }

public string Title { get; set; }
public string Tagline { get; set; }
public string Overview { get; set; }

public DateTime ReleaseDate { get; set; }

public int Runtime { get; set; }
public long Budget { get; set; }
public long Revenue { get; set; }
}

Can you spot the issue?

As it turns out it’s the id property, or more exactly the lack of an id property. A valid Cosmos document must always define an id (yes, case sensitive) property.

The fix is relatively easy, either rename the property to id (not very nice) or use an attribute to tell the serializer to change it:

1
2
[JsonProperty("id")]
public string Id { get; set; }

Hopefully this article will show up when you desperately google “CosmosDB [One of the specified inputs is invalid]” as I have :)

Share Comments