Contentful logo

Contentful Community

Model with property sys of type SystemProperty not accepted by CreateOrUpdateEntry

The model:

namespace ExampleNamespace
{
    public class ExampleModel
    {
        public SystemProperties Sys { get; set; }
        public Dictionary<string, string> Id { get; set; }
        public Dictionary<string, string> Name { get; set; }
        public Dictionary<string, string> Email { get; set; }
        public Dictionary<string, string> Country { get; set; }
        public Dictionary<string, string> EmployeeId { get; set; }
        public Dictionary<string, Reference> Image { get; set; }
    }
}
...
var entry = await _contentfulManagementClient.CreateOrUpdateEntry<ExampleModel>(
                    exampleModel,
                    exampleModel.Sys.Id, // I've manually assigned this value 
                    contentTypeId: "ExampleModel");
...
Contentful.Core: No field with id "sys" found.[
  {
    "name": "unknown",
    "path": [
      "fields",
      "sys"
    ]
  }
].

I can create an entry in Contentful with this model if I remove the Sys property. However, I am unable to update the entry due to version information within the Sys property will be missing. If I add the sys property Contentful returns a 422 with the information above. What am I doing wrong here?

I’ve solved this for now by having a base class without the sys property, and having another class that extends this class which contains the sys properties. Then I convert between these classes depending on the use case.

I’m not happy with this solution, but it works for now. I expected the Sdk to “detect” the sys property of the model and treat it accordingly. The .NET Sdk seems rather clunky. The example code in Git is also very limited, and the documentation does not provide any examples of the model code. Overall the process so far with the management API has consisted of a lot of trial and error.