using RestSharp and RestSharp.Serializers.NewtonsoftJson (both 106.12.0), I am trying to make use of Confluence.
My content class:
public class Content
{
[JsonProperty(PropertyName = "MyId")]
public int Id { get; set; }
[JsonProperty(PropertyName ="type")]
[SerializeAs(Name ="type")]
[JsonConverter(typeof(StringEnumConverter))]
public ContentType Type { get; set; }
public Space Space { get; set; }
public string Title { get; set; }
public Body Body { get; set; }
}
}
The enum causing trouble:
public enum ContentType
{
Unknown,
Page,
BlogPost
}
The rest client is configured to use JSON by calling
restClient.UseSerializer(() => new JsonSerializer());
Whenever I try to create a new Confluence page using this code...
public void CreatePage(Content content)
{
var request = new RestRequest("rest/api/content", Method.POST);
request.AddJsonBody(content);
IRestResponse<Content> response = RestClient.Post<Content>(request);
if (Logger.IsDebugEnabled) Logger.Debug($"StatusCode: {response.StatusCode}");
if (Logger.IsDebugEnabled) Logger.Debug($"ResponseStatus: {response.ResponseStatus}");
if (Logger.IsDebugEnabled) Logger.Debug($"ErrorMessage: {response.ErrorMessage}");
if (Logger.IsDebugEnabled) Logger.Debug($"Content: {response.Content}");
}
... I am getting a "badRequest" answer, response.content:
{"statusCode":400,"data":{"authorized":true,"valid":false,"errors":[{"message":{"key":"type is required to create content","args":[]}}],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not create content with type null"}
If i debug the request body value after the call, I can see the following:
{"Id":0,"Type":1,"Space":{"ID":null,"Key":"TESTSPACE2","Name":null,"Type":null,"Status":null},"Title":"FirstAutoPage","Body":{"Storage":{"Value":"\n <strong>This is a test!</strong>\n Did it work?"}}}
Obviously, none of my Content property attributes are used, neither the one for converting Id to "MyId" nor the ones for handling the ContentType enum (there still is "Type"=1, it should have been something like "type=Page".
So, what am I doing wrong?