3

I am attempting a post request, and I have the following body:

{
    "request": {
        "__metadata": {
            "type": "Microsoft.Office.Server.Search.REST.SearchRequest"
        },
        "Querytext": "query",
        "TrimDuplicates": false,
        "RowLimit": 100,
        "SelectProperties": {
            "results": [
                "Title"
            ]
        },
        "SortList": {
            "results": [
                {
                    "Property": "Title",
                    "Direction": "0"
                }
            ]
        },
        "SourceId": "d2045d82-3148-4a4d-9dfc-fecb81da2720"
    }
}

I get the following response:

{"error":{"code":"-1, Microsoft.Data.OData.ODataException","message":{"lang":"en-US","value":"The property '__metadata' does not exist on type 'Microsoft.Office.Server.Search.REST.SearchRequest'. Make sure to only use property names that are defined by the type."}}}

I have found this answer, however I already have my body formatted in the way the answer suggests.

1 Answer 1

2

Turned out to be an issue with RestSharp, and it overwriting the Content-Type header. The following resolved the issue:

var request = new RestRequest
{
    Method = Method.POST
};
request.Parameters.Clear();
request.AddParameter(
    "application/json;odata=verbose",
    javaScriptSerializer.Serialize( requestBody ),
    ParameterType.RequestBody );

Doing it the normal way sets the Content-Type to "application/json", which causes the error I was getting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.