From 500e6892ce8891e0c5fa97d7fec100035acf5acb Mon Sep 17 00:00:00 2001 From: Michael Kaltner Date: Thu, 12 Feb 2026 11:28:24 -0800 Subject: [PATCH] Add automatic API version detection for Arr apps Fixes #369 - Try API v3 first (current standard), fall back to v1 for older versions - Add logging to show which API version connected successfully - Update verifyApiAccess function in universal/functions.bash This resolves connection failures with newer Lidarr/Radarr/Sonarr installations that use API v3 instead of the hardcoded v1. --- universal/functions.bash | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/universal/functions.bash b/universal/functions.bash index ed3df173..8ecd28aa 100644 --- a/universal/functions.bash +++ b/universal/functions.bash @@ -21,15 +21,15 @@ logfileSetup () { getArrAppInfo () { # Get Arr App information if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then - arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" - if [ "$arrUrlBase" == "null" ]; then + arrUrlBase="$(sed -n 's:.*\(.*\).*:\1:p' /config/config.xml | head -n1)" + if [ -z "$arrUrlBase" ]; then arrUrlBase="" else - arrUrlBase="/$(echo "$arrUrlBase" | sed "s/\///")" + arrUrlBase="/$(echo "$arrUrlBase" | sed 's:^/*::; s:/*$::')" fi - arrName="$(cat /config/config.xml | xq | jq -r .Config.InstanceName)" - arrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)" - arrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)" + arrName="$(sed -n 's:.*\(.*\).*:\1:p' /config/config.xml | head -n1)" + arrApiKey="$(sed -n 's:.*\(.*\).*:\1:p' /config/config.xml | head -n1)" + arrPort="$(sed -n 's:.*\(.*\).*:\1:p' /config/config.xml | head -n1)" arrUrl="http://127.0.0.1:${arrPort}${arrUrlBase}" fi } @@ -39,15 +39,19 @@ verifyApiAccess () { do arrApiTest="" arrApiVersion="" - if [ -z "$arrApiTest" ]; then - arrApiVersion="v3" - arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)" - fi + + # Try API v3 first (current standard for Lidarr/Radarr/Sonarr) + arrApiVersion="v3" + arrApiTest="$(curl -fsS "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" 2>/dev/null | jq -er '.instanceName // .appName // empty' 2>/dev/null || true)" + + # Fall back to v1 for older installations if [ -z "$arrApiTest" ]; then arrApiVersion="v1" - arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)" + arrApiTest="$(curl -fsS "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" 2>/dev/null | jq -er '.instanceName // .appName // empty' 2>/dev/null || true)" fi - if [ ! -z "$arrApiTest" ]; then + + if [ -n "$arrApiTest" ]; then + log "Connected to $arrName using API $arrApiVersion" break else log "$arrName is not ready, sleeping until valid response..."