RestSharp issue: Updating Notion page throws JSON parsing error

I’m having trouble updating a Notion page using RestSharp. The API keeps returning an ‘Error parsing JSON body’ message. Here’s my code:

RestRequest MakeRequest(string url, Method method, string jsonBody)
{
    var req = new RestRequest(url, method);
    req.AddHeader("Auth", $"Bearer {secretKey}");
    req.AddHeader("Content-Type", "application/json");
    req.AddHeader("Notion-Api-Version", "2021-08-16");
    req.AddJsonBody(jsonBody);
    return req;
}

async Task EditPageContent(string pageId, string jsonBody, Action<string> onComplete)
{
    var endpoint = $"{baseUrl}/{pageId}";
    var req = MakeRequest(endpoint, Method.Patch, jsonBody);
    var api = new RestClient();
    var result = await api.ExecuteAsync(req);
    onComplete(result.Content);
}

My JSON body looks like this:

{"properties": {"Available": { "checkbox": true }}}

Oddly enough, when I use HttpWebRequest instead of RestSharp with the same JSON, it works fine. Any ideas what might be causing this? Thanks for your help!

I’ve dealt with this exact problem before. The issue likely stems from how RestSharp handles JSON serialization. Instead of passing a string, try using RestSharp’s object serialization:

req.AddJsonBody(new
{
    properties = new
    {
        Available = new { checkbox = true }
    }
});

This approach lets RestSharp handle the JSON conversion, which often resolves parsing errors. If that doesn’t work, verify your Notion API version is current. They update periodically, and outdated versions can cause unexpected behavior.

Another tip: use a network monitoring tool like Fiddler to inspect the actual request being sent. This can help identify any discrepancies between what you think you’re sending and what’s actually going over the wire.

I encountered a similar issue when working with RestSharp and Notion’s API. The problem might be in how RestSharp is serializing your JSON body. Try using RestSharp’s built-in JSON serializer instead of passing a raw string.

Here’s what worked for me:

req.AddJsonBody(new
{
    properties = new
    {
        Available = new { checkbox = true }
    }
});

This lets RestSharp handle the JSON serialization, which can sometimes resolve parsing issues. Also, double-check your API version - Notion occasionally updates their API, and using an outdated version can cause unexpected errors.

If this doesn’t solve it, you might want to inspect the exact JSON being sent by RestSharp using Fiddler or a similar tool. Sometimes, there are subtle differences in how different libraries format JSON that can cause issues with picky APIs.

hey, i had a similar problem. try using newtonsoft.json to serialize ur object instead of passing a string. like this:

var json = JsonConvert.SerializeObject(new { properties = new { Available = new { checkbox = true } } });
req.AddParameter(“application/json”, json, ParameterType.RequestBody);

this worked 4 me. good luck!