Help with Command API using RestSharp

I have been able to successfully use RestSharp to use various API entry points (get series list, get episode list, monitor/unmonitor episode), but I am having trouble issuing a simple command to refresh a series. Hopefully it is something painfully obvious that I am missing.

Code snippet:

request = new RestRequest (@"api/command", Method.POST); request.AddHeader (NZBDRONE_API_KEY_HEADER, NZBDRONE_API_KEY); request.RequestFormat = DataFormat.Json; request.AddParameter ("name", "rescanseries"); request.AddParameter ("seriesId", series.id);

Where series.id is the int ID from searching through the list of series returned via the API. But I get the following error:

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: n. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonTextReader.ReadInternal() at Newtonsoft.Json.JsonTextReader.Read() at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at NzbDrone.Api.Extensions.ReqResExtensions.FromJson(Stream body, Type type) in m:\\BuildAgent1\\work\\328d72309b633a8\\src\zbDrone.Api\\Extensions\\ReqResExtensions.cs:line 31 at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body, Type type) in m:\\BuildAgent1\\work\\328d72309b633a8\\src\zbDrone.Api\\Extensions\\ReqResExtensions.cs:line 24 at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body) in m:\\BuildAgent1\\work\\328d72309b633a8\\src\zbDrone.Api\\Extensions\\ReqResExtensions.cs:line 19 at NzbDrone.Api.REST.RestModule1.ReadResourceFromRequest() in m:\BuildAgent1\work\328d72309b633a8\src\zbDrone.Api\REST\RestModule.cs:line 188
at NzbDrone.Api.REST.RestModule1.<set_CreateResource>b__f(Object options) in m:\\BuildAgent1\\work\\328d72309b633a8\\src\zbDrone.Api\\REST\\RestModule.cs:line 155 at CallSite.Target(Closure , CallSite , Func2 , Object )
at Nancy.Routing.Route.<>c__DisplayClass4.b__3(Object parameters, CancellationToken context)
`

I’ve tried removing the ‘seriesId’ to see if that was the issue, but I get the same error. I can follow the PowerShell example to successfully rescan, but I really would like to use C# in this case. Any ideas what I might be doing wrong?

Use Request.AddBody instead of AddParameter:

request.AddBody(new { name = "rescanseries", seriesId = series.Id });

I was doing something similar with XBMC’s API and had to go this route.

That did the trick. Thanks much.