Help with api in bash script

I’m trying to use the Sonarr API to tell Sonarr that I’ve downloaded a new file of a show monitored by Sonarr. (outside of the Sonarr process)

curl -s http://192.168.1.1:8989/api/series -X POST -d {"name": "downloadedepisodesscan", "path": "/media/downloads/sonarr/$title", downloadClientId: "nzoid"} --header "X-Api-Key:xxxxxx"

I got an error message like this

{

“message”: “Unexpected end when deserializing object. Path ‘name’, line 1, position 6.”,
“description”: "Newtonsoft.Json.JsonSerializationException: Unexpected end when deserializing object. Path ‘name’, line 1, position 6.\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ThrowUnexpectedEndException (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, System.Object currentObject, System.String message) <0x40994b90 + 0x00057> in :0 "

I’m calling this from a bash script where I will pass the variable

title=“Jeopardy!”

Your JSON is invalid… downloadClientId needs to be in quotes.

Same error, just different character
So now I have it modified as such:

curldata=“"name": "downloadedepisodesscan", "path": "/media/downloads/$sortpath/$title", "downloadClientId": "nzoid"”

which results in

echo $curldata
“name”: “downloadedepisodesscan”, “path”: “/media/downloads/sonarr/Jeopardy!”, “downloadClientId”: “nzoid”

so I run

curl -s http://192.168.10.120:8989/api/series -X POST -d {$curldata} --header “X-Api-Key:XXXXX”

The result:

{
“message”: “Unexpected end when deserializing object. Path ‘name’, line 1, position 8.”,
“description”: "Newtonsoft.Json.JsonSerializationException: Unexpected end when deserializing object. Path ‘name’, line 1, position 8.\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ThrowUnexpectedEndException (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, System.Object currentObject, System.String message) <0x40994b90 + 0x00057> in :0 "
}

Does the folder have to be in a specific format?

You don’t think you need to properly escape the -d curl parameter?

I’m trying to get it working without variables. Just flat text

[
{
“propertyName”: “ProfileId”,
“errorMessage”: “‘Profile Id’ must be greater than ‘0’.”,
“attemptedValue”: 0,
“errorCode”: “greaterthan_error”,
“formattedMessageArguments”: ,
“formattedMessagePlaceholderValues”: {
“propertyName”: “Profile Id”,
“propertyValue”: 0,
“comparisonValue”: 0
},
“resourceName”: “greaterthan_error”
},
{
“propertyName”: “ProfileId”,
“errorMessage”: “Profile does not exist”,
“attemptedValue”: 0,
“formattedMessageArguments”: ,
“formattedMessagePlaceholderValues”: {
“propertyName”: “Profile Id”,
“propertyValue”: 0
}
},
{
“propertyName”: “Title”,
“errorMessage”: “‘Title’ should not be empty.”,
“errorCode”: “notempty_error”,
“formattedMessageArguments”: ,
“formattedMessagePlaceholderValues”: {
“propertyName”: “Title”,
“propertyValue”: null
},
“resourceName”: “notempty_error”
},
{
“propertyName”: “TvdbId”,
“errorMessage”: “‘Tvdb Id’ must be greater than ‘0’.”,
“attemptedValue”: 0,
“errorCode”: “greaterthan_error”,
“formattedMessageArguments”: ,
“formattedMessagePlaceholderValues”: {
“propertyName”: “Tvdb Id”,
“propertyValue”: 0,
“comparisonValue”: 0
},
“resourceName”: “greaterthan_error”
}

Once I get it working with variables, I can work backwards to script it.

-d {…} is wrong… {} is used for bash globbing and needs to be escaped. There’s an example on our wiki.

Do you mean https://github.com/Sonarr/Sonarr/wiki/Manually-Triggering-Imports

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

I ran the command:
curl -s http://192.168.1.1:8989/api/series -X POST -d ‘{“name”: “downloadedepisodesscan”, “path”: “/media/downloads/sonar/Jeopardy!”, “downloadClientId”: “nzoid”}’ --header “X-Api-Key:XXXX”

What am I missing?

In your original post you don’t have the single quotes.

Also, series vs command endpoint

I’ve been modifying it as i go trying to fix it. Also, I’m new to APIs. can you explain the series vs command end point comment?

You’re posting it to the wrong url. Compare what you’re doing with the example.

oh balls. Thanks!

How can I tell if the command worked? Is there a response line to look for?

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