Cant call Drone Factory from command

I am trying to run a drone factory from command using curl.

curl http://localhost:8989/api/command -X POST -d ‘{“name”: “downloadedepisodesscan”}’ --header “X-Api-Key:my5454key”

This only gives me an error.

{
“error”: “Unauthorized”
}curl: (3) [globbing] unmatched close brace/bracket in column 23

Can anyone help me to get this working?

It’s unauthorized, either the API you are sending is wrong or the header is not being set properly.

I copied the API directly from Sonarr.

Can you explain what you mean by “header is not being set properly” and how I can fix it?

Add -v as cmdline parameter, that’ll tell curl to dump the request headers. MANUALLY verify if the apikey is EXACTLY the same as the one in Sonarr Settings->General.

Then I tried

curl -v http://localhost:8989/api/command -X POST -d '{"name": "downloadedepisodesscan"}' --header "X-Api-Key:MyKey"

Return the following in cmd:

Note: Unnecessary use of -X or --request, POST is already inferred.
* timeout on name lookup is not supported
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8989 (#0)
> POST /api/command HTTP/1.1
> Host: localhost:8989
> User-Agent: curl/7.53.1
> Accept: */*
> X-Api-Key:myapi
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 7 out of 7 bytes
< HTTP/1.1 500 Internal Server Error
< Cache-Control: no-cache, no-store, must-revalidate
< Pragma: no-cache
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=utf-8
< Expires: 0
< Server: Microsoft-HTTPAPI/2.0
< X-ApplicationVersion: 2.0.0.4689
< Date: Wed, 12 Apr 2017 17:37:42 GMT
<
{
  "message": "Unterminated string. Expected delimiter: '. Path '', line 1, position 7.",
  "description": "Newtonsoft.Json.JsonReaderException: Unterminated string. Expected delimiter: '. Path '', line 1, position 7.\r\n   at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)\r\n   at Newtonsoft.Json.JsonTextReader.ParseString(Char quote, ReadType readType)\r\n   at Newtonsoft.Json.JsonTextReader.ParseValue()\r\n   at Newtonsoft.Json.JsonTextReader.Read()\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)\r\n   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson(Stream body, Type type) in M:\\BuildAgent\\work\\b69c1fe19bfc2c38\\src\\NzbDrone.Api\\Extensions\\ReqResExtensions.cs:line 31\r\n   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body, Type type) in M:\\BuildAgent\\work\\b69c1fe19bfc2c38\\src\\NzbDrone.Api\\Extensions\\ReqResExtensions.cs:line 24\r\n   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body) in M:\\BuildAgent\\work\\b69c1fe19bfc2c38\\src\\NzbDrone.Api\\Extensions\\ReqResExtensions.cs:line 19\r\n   at NzbDrone.Api.REST.RestModule`1.ReadResourceFromRequest(Boolean skipValidate) in M:\\BuildAgent\\work\\b69c1fe19bfc2c38\\src\\NzbDrone.Api\\REST\\RestModule.cs:line 188\r\n   at NzbDrone.Api.REST.RestModule`1.<set_CreateResource>b__41_0(Object options) in M:\\BuildAgent\\work\\b69c1fe19bfc2c38\\src\\NzbDrone.Api\\REST\\RestModule.cs:line 155\r\n   at CallSite.Target(Closure , CallSite , Func`2 , Object )\r\n   at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)"
}* Connection #0 to host localhost left intact
curl: (3) [globbing] unmatched close brace/bracket in column 23

In Sonarr:

Newtonsoft.Json.JsonReaderException: Unterminated string. Expected delimiter: '. Path '', line 1, position 7.
   at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)
   at Newtonsoft.Json.JsonTextReader.ParseString(Char quote, ReadType readType)
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   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:\BuildAgent\work\b69c1fe19bfc2c38\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 31
   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body, Type type) in M:\BuildAgent\work\b69c1fe19bfc2c38\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 24
   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body) in M:\BuildAgent\work\b69c1fe19bfc2c38\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 19
   at NzbDrone.Api.REST.RestModule`1.ReadResourceFromRequest(Boolean skipValidate) in M:\BuildAgent\work\b69c1fe19bfc2c38\src\NzbDrone.Api\REST\RestModule.cs:line 188
   at NzbDrone.Api.REST.RestModule`1.<set_CreateResource>b__41_0(Object options) in M:\BuildAgent\work\b69c1fe19bfc2c38\src\NzbDrone.Api\REST\RestModule.cs:line 155
   at CallSite.Target(Closure , CallSite , Func`2 , Object )
   at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)

I dont understand any of this. How hard can it be to run a scan drone factory command?

At least you no longer have the unauthorized error.

Euh, the source string isn’t 7 bytes in length, it’s more like 34.
probably bash/shell doing the -d '...' differently. Try -d "{\"name\": \"downloadedepisodesscan\"}"

Ahh, and it works!

Thank you so much. This was driving me crazy.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.