From fa568056d3a370c506a09d5d4288d1cf43ebb785 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Mon, 2 Feb 2026 22:51:23 +0800 Subject: [PATCH] update API tools script --- scripts/ebktools.ps1 | 110 +++++++++++++++++++++++----------- scripts/ebktools.sh | 139 ++++++++++++++++++++++++++++--------------- 2 files changed, 164 insertions(+), 85 deletions(-) diff --git a/scripts/ebktools.ps1 b/scripts/ebktools.ps1 index 139d3a25..6f507dec 100755 --- a/scripts/ebktools.ps1 +++ b/scripts/ebktools.ps1 @@ -78,9 +78,9 @@ $API_CONFIGS = @( " `"category`": `"integer (Account category, 1: Cash, 2: Checking Account, 3: Credit Card, 4: Virtual Account, 5: Debt Account, 6: Receivables, 7: Investment Account, 8: Savings Account, 9: Certificate of Deposit)`"," " `"type`": `"integer (Account type, 1: Single Account, 2: Multiple Sub-accounts)`"," " `"icon`": `"string (Account icon ID)`"," - " `"color`": `"string (Account icon color, Hex color code RRGGBB)`"," + " `"color`": `"string (Account icon color, hex color code RRGGBB)`"," " `"currency`": `"string (Account currency code)`"," - " `"balance`": `"integer (Account balance, supports up to two decimals. For example, a value of `"1234`" represents an amount of `"12.34`")`"," + " `"balance`": `"integer (Account balance, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`"," " `"comment`": `"string (Account description)`"," " `"creditCardStatementDate`": `"integer (The statement date of the credit card account)`"," " `"displayOrder`": `"integer (The display order of the account)`"," @@ -254,8 +254,10 @@ $API_CONFIGS = @( ResponseStructure = @( "{" " `"id`": `"string (Transaction tag ID)`"," - " `"name`": `"string`"," - " ..." + " `"name`": `"string (Transaction tag name)`"," + " `"groupId`": `"string (Transaction tag group ID)`"," + " `"displayOrder`": `"integer (The display order of the transaction tag)`"," + " `"hidden`": `"boolean (Whether the transaction tag is hidden)`"" "}" ) } @@ -316,8 +318,8 @@ $API_CONFIGS = @( " `"sourceAccount`": `"object (Source account object)`"," " `"destinationAccountId`": `"string (Destination account ID)`"," " `"destinationAccount`": `"object (Destination account object)`"," - " `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`"," - " `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`"," + " `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`"," + " `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`"," " `"hideAmount`": `"boolean (Whether to hide the amount)`"," " `"tagIds`": [`"each string representing a transaction tag ID`"]," " `"tags`": [`"each object representing a transaction tag object`"]," @@ -327,7 +329,7 @@ $API_CONFIGS = @( " `"editable`": `"boolean (Whether the transaction is editable)`"" " }" " ]," - " `"nextTimeSequenceId`": `"integer (The next cursor ``max_time`` parameter when requesting older data)`"," + " `"nextTimeSequenceId`": `"integer (The next cursor 'max_time' parameter when requesting older data)`"," " `"totalCount`": `"integer (The total count of transactions)`"" "}" ) @@ -382,8 +384,8 @@ $API_CONFIGS = @( " `"sourceAccount`": `"object (Source account object)`"," " `"destinationAccountId`": `"string (Destination account ID)`"," " `"destinationAccount`": `"object (Destination account object)`"," - " `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`"," - " `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`"," + " `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`"," + " `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`"," " `"hideAmount`": `"boolean (Whether to hide the amount)`"," " `"tagIds`": [`"each string representing a transaction tag ID`"]," " `"tags`": [`"each object representing a transaction tag object`"]," @@ -460,7 +462,7 @@ $API_CONFIGS = @( } ) -# Reference: https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml +# Reference: https://github.com/unicode-org/cldr/blob/main/common/supplemental/windowsZones.xml $TIMEZONE_IANA_NAMES = @{ "Dateline Standard Time" = "Etc/GMT+12" "UTC-11" = "Etc/GMT+11" @@ -473,7 +475,7 @@ $TIMEZONE_IANA_NAMES = @{ "UTC-08" = "Etc/GMT+8" "Pacific Standard Time" = "America/Los_Angeles" "US Mountain Standard Time" = "America/Phoenix" - "Mountain Standard Time (Mexico)" = "America/Chihuahua" + "Mountain Standard Time (Mexico)" = "America/Mazatlan" "Mountain Standard Time" = "America/Denver" "Yukon Standard Time" = "America/Whitehorse" "Central America Standard Time" = "America/Guatemala" @@ -732,17 +734,37 @@ function Get-SystemTimezoneName { } catch { # Do Nothing } - return "Asia/Shanghai" + return $null +} + +function Get-ExampleTimezoneName { + $name = Get-SystemTimezoneName + + if ($null -ne $name) { + return "$name" + } else { + return "Asia/Shanghai" + } } function Get-SystemTimezoneOffset { try { $offset = [System.TimeZoneInfo]::Local.BaseUtcOffset - return [int]$offset.TotalMinutes + return [string]$offset.TotalMinutes.ToString() } catch { # Do Nothing } - return 480 + return $null +} + +function Get-ExampleTimezoneOffset { + $offset = Get-SystemTimezoneOffset + + if ($null -ne $offset) { + return "$offset" + } else { + return "480" + } } function Get-ApiConfig { @@ -758,8 +780,8 @@ function Get-ApiConfig { } function Show-Help { - $tzName = Get-SystemTimezoneName - $tzOffset = Get-SystemTimezoneOffset + $exampleTimezoneName = Get-ExampleTimezoneName + $exampleTimezoneOffset = Get-ExampleTimezoneOffset Write-Host "ezBookkeeping API Tools" Write-Host "" @@ -768,14 +790,14 @@ function Show-Help { Write-Host "Usage:" Write-Host " ebktools.ps1 [-tzName ] [-tzOffset ] [command-options]" Write-Host "" - Write-Host "Global Options:" - Write-Host " -tzName The IANA timezone name, for example, for Beijing Time it is 'Asia/Shanghai'." - Write-Host " -tzOffset The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both are provided, '-tzName' takes precedence." - Write-Host "" Write-Host "Environment Variables (Required):" Write-Host " EBKTOOL_SERVER_BASEURL ezBookkeeping server base URL (e.g., http://localhost:8080)" Write-Host " EBKTOOL_TOKEN ezBookkeeping API token" Write-Host "" + Write-Host "Global Options:" + Write-Host " -tzName The IANA timezone name of current timezone. For example, for Beijing Time it is 'Asia/Shanghai'." + Write-Host " -tzOffset The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both '-tzName' and '-tzOffset' are set, '-tzName' takes priority. If neither is set, the current system time zone is used by default." + Write-Host "" Write-Host "Commands:" Write-Host " list List all available API commands" Write-Host " help Show help for a specific API command" @@ -796,10 +818,10 @@ function Show-Help { Write-Host " ebktools.ps1 accounts-list" Write-Host "" Write-Host " # Call API with timezone name" - Write-Host " ebktools.ps1 -tzName $tzName transactions-list -count 10" + Write-Host " ebktools.ps1 -tzName $exampleTimezoneName transactions-list -count 10" Write-Host "" Write-Host " # Call API with timezone offset" - Write-Host " ebktools.ps1 -tzOffset $tzOffset transactions-list -count 10" + Write-Host " ebktools.ps1 -tzOffset $exampleTimezoneOffset transactions-list -count 10" } function Show-CommandList { @@ -831,6 +853,7 @@ function Show-CommandHelp { Write-Host "Description: $($config.Description)" Write-Host "Method: $($config.Method)" Write-Host "Path: $($config.Path)" + Write-Host ("Require current time zone: " + ($(if ($config.RequiresTimezone) { 'Yes' } else { 'No' }))) Write-Host "" if ($config.RequiredParams.Count -gt 0) { @@ -860,9 +883,14 @@ function Show-CommandHelp { } Write-Host "Example:" - if ($config.RequiresTimezone) { - $tzName = Get-SystemTimezoneName - Write-Host " ebktools.ps1 -tzName $tzName $($config.Name)" + $currentTzName = Get-SystemTimezoneName + $currentTzOffset = Get-SystemTimezoneOffset + if ($config.RequiresTimezone -and $null -ne $currentTzName) { + Write-Host " ebktools.ps1 -tzName $currentTzName $($config.Name)" + } elseif ($config.RequiresTimezone -and $null -ne $currentTzOffset) { + Write-Host " ebktools.ps1 -tzOffset $currentTzOffset $($config.Name)" + } elseif ($config.RequiresTimezone) { + Write-Host " ebktools.ps1 -tzName $($config.Name)" } else { Write-Host " ebktools.ps1 $($config.Name)" } @@ -969,25 +997,35 @@ function Invoke-Api { if (-not $serverBaseUrl) { Write-Red "Error: Environment variable 'EBKTOOL_SERVER_BASEURL' is not set." - Write-Host "Please set it to your API server base URL (e.g., http://localhost:8080)" + Write-Host "Please set it to your ezBookkeeping server base URL (e.g., http://localhost:8080)" exit 1 } if (-not $authToken) { Write-Red "Error: Environment variable 'EBKTOOL_TOKEN' is not set." - Write-Host "Please set it to your authentication token." + Write-Host "Please set it to your API token." exit 1 } - if ($config.RequiresTimezone -and -not $script:tzName -and -not $script:tzOffset) { - $tzName = Get-SystemTimezoneName - $tzOffset = Get-SystemTimezoneOffset + $currentTimezoneName = Get-SystemTimezoneName + $currentTimezoneOffset = Get-SystemTimezoneOffset + + if ($script:tzName -ne $null -and $script:tzName -ne "") { + $currentTimezoneName = $script:tzName + } + + if ($script:tzOffset -ne $null -and $script:tzOffset -ne "") { + $currentTimezoneName = "" + $currentTimezoneOffset = $script:tzOffset + } + + if ($config.RequiresTimezone -and -not $currentTimezoneName -and -not $currentTimezoneOffset) { Write-Red "Error: Command '$commandName' requires timezone information." Write-Host "Please provide either '-tzName' or '-tzOffset' parameter." Write-Host "" Write-Host "Examples:" - Write-Host " ebktools.ps1 -tzName $tzName $commandName ..." - Write-Host " ebktools.ps1 -tzOffset $tzOffset $commandName ..." + Write-Host " ebktools.ps1 -tzName $commandName ..." + Write-Host " ebktools.ps1 -tzOffset $commandName ..." exit 1 } @@ -1016,10 +1054,10 @@ function Invoke-Api { "Authorization" = "Bearer $authToken" } - if ($script:tzName) { - $headers["X-Timezone-Name"] = $script:tzName - } elseif ($script:tzOffset) { - $headers["X-Timezone-Offset"] = $script:tzOffset + if ($currentTimezoneName) { + $headers["X-Timezone-Name"] = $currentTimezoneName + } elseif ($currentTimezoneOffset) { + $headers["X-Timezone-Offset"] = $currentTimezoneOffset } if ($config.Method -eq "POST") { diff --git a/scripts/ebktools.sh b/scripts/ebktools.sh index ad48eddf..1796fae8 100755 --- a/scripts/ebktools.sh +++ b/scripts/ebktools.sh @@ -66,7 +66,7 @@ API_CONFIGS='[ " \"icon\": \"string (Account icon ID)\",", " \"color\": \"string (Account icon color, hex color code RRGGBB)\",", " \"currency\": \"string (Account currency code)\",", - " \"balance\": \"integer (Account balance, supports up to two decimals. For example, a value of \\"1234\\" represents an amount of \\"12.34\\")\",", + " \"balance\": \"integer (Account balance, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",", " \"comment\": \"string (Account description)\",", " \"creditCardStatementDate\": \"integer (The statement date of the credit card account)\",", " \"displayOrder\": \"integer (The display order of the account)\",", @@ -240,8 +240,10 @@ API_CONFIGS='[ "ResponseStructure": [ "{", " \"id\": \"string (Transaction tag ID)\",", - " \"name\": \"string\",", - " ...", + " \"name\": \"string (Transaction tag name)\",", + " \"groupId\": \"string (Transaction tag group ID)\",", + " \"displayOrder\": \"integer (The display order of the transaction tag)\",", + " \"hidden\": \"boolean (Whether the transaction tag is hidden)\"", "}" ] }, @@ -302,8 +304,8 @@ API_CONFIGS='[ " \"sourceAccount\": \"object (Source account object)\",", " \"destinationAccountId\": \"string (Destination account ID)\",", " \"destinationAccount\": \"object (Destination account object)\",", - " \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",", - " \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",", + " \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",", + " \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",", " \"hideAmount\": \"boolean (Whether to hide the amount)\",", " \"tagIds\": [\"each string representing a transaction tag ID\"],", " \"tags\": [\"each object representing a transaction tag object\"],", @@ -313,7 +315,7 @@ API_CONFIGS='[ " \"editable\": \"boolean (Whether the transaction is editable)\"", " }", " ],", - " \"nextTimeSequenceId\": \"integer (The next cursor `max_time` parameter when requesting older data)\",", + " \"nextTimeSequenceId\": \"integer (The next cursor '"'"'max_time'"'"' parameter when requesting older data)\",", " \"totalCount\": \"integer (The total count of transactions)\"", "}" ] @@ -368,8 +370,8 @@ API_CONFIGS='[ " \"sourceAccount\": \"object (Source account object)\",", " \"destinationAccountId\": \"string (Destination account ID)\",", " \"destinationAccount\": \"object (Destination account object)\",", - " \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",", - " \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",", + " \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",", + " \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",", " \"hideAmount\": \"boolean (Whether to hide the amount)\",", " \"tagIds\": [\"each string representing a transaction tag ID\"],", " \"tags\": [\"each object representing a transaction tag object\"],", @@ -479,13 +481,26 @@ get_system_timezone_name() { readlink /etc/localtime | sed 's|.*/zoneinfo/||' elif command -v timedatectl > /dev/null 2>&1; then timedatectl | grep "Time zone" | awk '{print $3}' + fi +} + +get_example_timezone_name() { + tz_name="$(get_system_timezone_name)" + + if [ -n "$tz_name" ]; then + echo "$tz_name" else echo "Asia/Shanghai" fi } get_system_timezone_offset() { - offset_str="$(date +%z 2>/dev/null || echo "+0800")" + offset_str="$(date +%z 2>/dev/null)" + + if [ -z "$offset_str" ]; then + return + fi + sign="${offset_str%????}" hours="${offset_str#?}" hours="${hours%??}" @@ -504,14 +519,24 @@ get_system_timezone_offset() { fi } +get_example_timezone_offset() { + tz_offset="$(get_system_timezone_offset)" + + if [ -n "$tz_offset" ]; then + echo "$tz_offset" + else + echo "480" + fi +} + parse_api_config() { api_name="$1" echo "$API_CONFIGS" | jq -r --arg name "$api_name" '.[] | select(.Name == $name)' } show_help() { - tz_name="$(get_system_timezone_name)" - tz_offset="$(get_system_timezone_offset)" + example_timezone_name="$(get_example_timezone_name)" + example_timezone_offset="$(get_example_timezone_offset)" cat <<-EOF ezBookkeeping API Tools @@ -521,14 +546,14 @@ A command-line tool for calling ezBookkeeping APIs Usage: ebktools.sh [--tz-name ] [--tz-offset ] [command-options] -Global Options: - --tz-name The IANA timezone name, for example, for Beijing Time it is 'Asia/Shanghai'. - --tz-offset The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both are provided, '--tz-name' takes precedence. - Environment Variables (Required): EBKTOOL_SERVER_BASEURL ezBookkeeping server base URL (e.g., http://localhost:8080) EBKTOOL_TOKEN ezBookkeeping API token +Global Options: + --tz-name The IANA timezone name of current timezone. For example, for Beijing Time it is 'Asia/Shanghai'. + --tz-offset The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both '--tz-name' and '--tz-offset' are set, '--tz-name' takes priority. If neither is set, the current system time zone is used by default. + Commands: list List all available API commands help Show help for a specific API command @@ -549,10 +574,10 @@ Examples: ebktools.sh accounts-list # Call API with timezone name - ebktools.sh --tz-name ${tz_name} transactions-list --count 10 + ebktools.sh --tz-name ${example_timezone_name} transactions-list --count 10 # Call API with timezone offset - ebktools.sh --tz-offset ${tz_offset} transactions-list --count 10 + ebktools.sh --tz-offset ${example_timezone_offset} transactions-list --count 10 EOF } @@ -583,12 +608,14 @@ show_command_help() { desc="$(echo "$config" | jq -r '.Description')" method="$(echo "$config" | jq -r '.Method')" path="$(echo "$config" | jq -r '.Path')" + requires_timezone="$(echo "$config" | jq -r '.RequiresTimezone // false')" response_struct="$(echo "$config" | jq -r '.ResponseStructure')" echo "Command: $name" echo "Description: $desc" echo "Method: $method" echo "Path: $path" + echo "Require current time zone: $([ "$requires_timezone" = "true" ] && echo Yes || echo No)" echo "" required_count="$(echo "$config" | jq '.RequiredParams | length')" @@ -622,10 +649,14 @@ show_command_help() { fi echo "Example:" - requires_timezone="$(echo "$config" | jq -r '.RequiresTimezone // false')" - if [ "$requires_timezone" = "true" ]; then - tz_name="$(get_system_timezone_name)" - echo " ebktools.sh --tz-name ${tz_name} $name" + current_tz_name="$(get_system_timezone_name)" + current_tz_offset="$(get_system_timezone_offset)" + if [ "$requires_timezone" = "true" ] && [ -n "$current_tz_name" ]; then + echo " ebktools.sh --tz-name ${current_tz_name} $name" + elif [ "$requires_timezone" = "true" ] && [ -n "$current_tz_offset" ]; then + echo " ebktools.sh --tz-offset ${current_tz_offset} $name" + elif [ "$requires_timezone" = "true" ]; then + echo " ebktools.sh --tz-name $name" else echo " ebktools.sh $name" fi @@ -649,26 +680,36 @@ call_api() { if [ -z "$serverBaseUrl" ]; then echo_red "Error: Environment variable 'EBKTOOL_SERVER_BASEURL' is not set." - echo "Please set it to your API server base URL (e.g., http://localhost:8080)" + echo "Please set it to your ezBookkeeping server base URL (e.g., http://localhost:8080)" exit 1 fi if [ -z "$authToken" ]; then echo_red "Error: Environment variable 'EBKTOOL_TOKEN' is not set." - echo "Please set it to your authentication token." + echo "Please set it to your API token." exit 1 fi requires_timezone="$(echo "$config" | jq -r '.RequiresTimezone // false')" - if [ "$requires_timezone" = "true" ] && [ -z "$TIMEZONE_NAME" ] && [ -z "$TIMEZONE_OFFSET" ]; then - tz_name="$(get_system_timezone_name)" - tz_offset="$(get_system_timezone_offset)" + current_tz_name="$(get_system_timezone_name)" + current_tz_offset="$(get_system_timezone_offset)" + + if [ -n "$TIMEZONE_NAME" ]; then + current_tz_name="$TIMEZONE_NAME" + fi + + if [ -n "$TIMEZONE_OFFSET" ]; then + current_tz_name="" + current_tz_offset="$TIMEZONE_OFFSET" + fi + + if [ "$requires_timezone" = "true" ] && [ -z "$current_tz_name" ] && [ -z "$current_tz_offset" ]; then echo_red "Error: Command '$command_name' requires timezone information." echo "Please provide either '--tz-name' or '--tz-offset' parameter." echo "" echo "Examples:" - echo " ebktools.sh --tz-name ${tz_name} $command_name ..." - echo " ebktools.sh --tz-offset ${tz_offset} $command_name ..." + echo " ebktools.sh --tz-name $command_name ..." + echo " ebktools.sh --tz-offset $command_name ..." exit 1 fi @@ -800,10 +841,10 @@ call_api() { url="${serverBaseUrl}/api/v1/${path}" timezone_headers="" - if [ -n "$TIMEZONE_NAME" ]; then - timezone_headers="X-Timezone-Name: $TIMEZONE_NAME" - elif [ -n "$TIMEZONE_OFFSET" ]; then - timezone_headers="X-Timezone-Offset: $TIMEZONE_OFFSET" + if [ -n "$current_tz_name" ]; then + timezone_headers="X-Timezone-Name: $current_tz_name" + elif [ -n "$current_tz_offset" ]; then + timezone_headers="X-Timezone-Offset: $current_tz_offset" fi if [ "$method" = "POST" ]; then @@ -812,32 +853,32 @@ call_api() { if [ "$json_params" != "{}" ]; then if [ -n "$timezone_headers" ]; then - response=$(curl -s -X "POST" \ + response="$(curl -s -X "POST" \ -H "Authorization: Bearer $EBKTOOL_TOKEN" \ -H "Content-Type: application/json" \ -H "$timezone_headers" \ -d "$json_params" \ - "$url") + "$url")" curl_exit_code=$? else - response=$(curl -s -X "POST" \ + response="$(curl -s -X "POST" \ -H "Authorization: Bearer $EBKTOOL_TOKEN" \ -H "Content-Type: application/json" \ -d "$json_params" \ - "$url") + "$url")" curl_exit_code=$? fi else if [ -n "$timezone_headers" ]; then - response=$(curl -s -X "POST" \ + response="$(curl -s -X "POST" \ -H "Authorization: Bearer $EBKTOOL_TOKEN" \ -H "$timezone_headers" \ - "$url") + "$url")" curl_exit_code=$? else - response=$(curl -s -X "POST" \ + response="$(curl -s -X "POST" \ -H "Authorization: Bearer $EBKTOOL_TOKEN" \ - "$url") + "$url")" curl_exit_code=$? fi fi @@ -850,14 +891,14 @@ call_api() { echo "" if [ -n "$timezone_headers" ]; then - response=$(curl -s -X "$method" \ + response="$(curl -s -X "$method" \ -H "Authorization: Bearer $EBKTOOL_TOKEN" \ -H "$timezone_headers" \ - "$url") + "$url")" else - response=$(curl -s -X "$method" \ + response="$(curl -s -X "$method" \ -H "Authorization: Bearer $EBKTOOL_TOKEN" \ - "$url") + "$url")" fi curl_exit_code=$? fi @@ -867,22 +908,22 @@ call_api() { exit 1 fi - success=$(echo "$response" | jq -r '.success // "null"') + success=$(printf "%s\n" "$response" | jq -r '.success // "null"') if [ "$success" = "true" ]; then echo "Response Result:" - result=$(echo "$response" | jq '.result // "null"') + result=$(printf "%s\n" "$response" | jq '.result // "null"') if [ "$result" != "null" ]; then - echo "$response" | jq '.result' + printf "%s\n" "$response" | jq '.result' else echo "Success: true (No result data)" fi elif [ "$success" = "false" ]; then echo "Raw Response:" - echo "$response" | jq '.' + printf "%s\n" "$response" | jq '.' else echo "Raw Response:" - echo "$response" | jq '.' + printf "%s\n" "$response" | jq '.' fi }