Below is the code that I have:
List<PatchOperation> patchOperations = new List<PatchOperation>();
patchOperations.Add(PatchOperation.Replace("/endpointId", 100));
string id = "id1";
PartitionKey partitionKey = new PartitionKey("partitionkey1");
await _container.PatchItemAsync<Watermark>(id,
partitionKey,
patchOperations);
I am expecting to get endpointId
property to be replaced with 100.
However, I am faced with Message: {"Errors":["One of the specified inputs is invalid"]}
.
May I check which part am I missing or do I have to wait for patch private preview feature to be enabled for my cosmos db?
CodePudding user response:
For anyone else landing here looking for the reason why Cosmos might respond with One of the specified inputs is invalid
for other request types, you may need to rename your Id
property to id
lower-cased or add an attribute:
[JsonProperty("id")]
public string Id { get; set; }
CodePudding user response:
id attribite in cosmos db is case sensitive. Try to replace your id getter setter with "id" this case.
CodePudding user response:
Even though error says "One of the specified inputs is invalid"
you should see a status code 400 which indicates Bad Request
. So Private Preview feature needs to be enabled for your account.
You can also enable Patch with your emulator by adding EnablePreview
when you start the emulator,
.\CosmosDB.Emulator.exe /EnablePreview
In order to get it enabled you can register using this form and it should be done in 15-20 minutes. Let me know if that does not work
CodePudding user response:
Another reason for this error message could be if you forget the forward slash before your property name:
await container.PatchItemAsync<T>(item.Id, new PartitionKey(item.PartitionKey), new[]
{
PatchOperation.Add("isDeleted", true),
PatchOperation.Add("ttl", DefaultTtl),
});
The correct code would be:
await container.PatchItemAsync<T>(item.Id, new PartitionKey(item.PartitionKey), new[]
{
PatchOperation.Add("/isDeleted", true),
PatchOperation.Add("/ttl", DefaultTtl),
});