Script triggered by API not executed properly

Glad that you find it useful, I did additionally some small changes to print out messages in terminal, not just in log and moved config vars on top for convenience, but core of script logic remains as in linked topic from OP, here is my latest ver:

:global GcontainerUpdate do={
# After ROS upgrade check below if something has changed
# ------------------------------------------------------
# validAddArgs - array of container add command argument names which are named exact as config property names
  :local validAddArgs ( "cmd", "comment", "dns", "domain-name", "entrypoint", "envlist", "hostname", "interface", "logging", "mounts", "root-dir", "start-on-boot", "workdir" )
# replaceArgs - key-value array for mapping container add command argument name from different config property name,
# where key is config property name and value is argument name
  :local replaceArgs { "tag"="remote-image" }
# addCmd - ROS CLI container add command
  :local addCmd "/container add"
# ------------------------------------------------------
# stopTimeoutSec - container stop wait timeout in seconds
  :local stopTimeoutSec 120
# extrTimeoutSec - container download/extract wait timeout in seconds, rise if not enough (1800 = 30min) on slow network or device
  :local extrTimeoutSec 1800
# logPrefix - script log record prefix
  :local logPrefix "Container update: "

  :local abortWithMessage do={
    :log error "$($logPrefix)Error - $1"
    :error $1
  }

  :local logWithMessage do={
    :if ($level = "W") do={ :log warn "$logPrefix$1" } else={ :log info "$logPrefix$1" }
    :put "[$level] $1"
  }

  :local contComment $1

  /container
  :local contId [find where comment=$contComment]
  :if ($contId = "") do={ $abortWithMessage ("container $contComment not found, aborting") logPrefix=$logPrefix }

  :local contStatus ([get $contId]->"status")
  :if ($contStatus = "extracting") do={ $abortWithMessage ("container $contComment is extracting, aborting") logPrefix=$logPrefix }

  $logWithMessage ("Container $contComment update started") logPrefix=$logPrefix level="I"
  :local contStarted false

  :if ($contStatus != "stopped") do={
    :if ($contStatus = "running") do={
      $logWithMessage ("Container $contComment is running, stopping container") logPrefix=$logPrefix level="W"
      :set contStarted true
      stop $contId as-value
    }

    :local sec 0

    :while (([get $contId]->"status") != "stopped" && $sec <= $stopTimeoutSec) do={
      :delay 1
      :set sec ($sec + 1)
    }

    :if ($sec > $stopTimeoutSec) do={ $abortWithMessage ("container $contComment stop timed out, aborting") logPrefix=$logPrefix }
    $logWithMessage ("Container $contComment stopped") logPrefix=$logPrefix level="W"
  }

  $logWithMessage ("Removing old and adding new container $contComment") logPrefix=$logPrefix level="I"
  :local cont [get $contId]
  remove $contId
  :delay 5

  :local escapeStr do={
    :local strLen [:len $1]
    :local escStr ""

    :for i from=0 to=($strLen - 1) do={
      :local chr [:pick $1 $i ($i + 1)]

      :if ($chr = "\$") do={ :set escStr "$escStr\\\$" } else={
        :if ($chr = "\\") do={ :set escStr "$escStr\\\\" } else={
          :if ($chr = "\"") do={ :set escStr "$escStr\\\"" } else={
            :set escStr "$escStr$chr"
          }
        }
      }
    }

    :return "\"$escStr\""
  }

  :local arrayToStr do={
    :local arrLen [:len $1]
    :local strArr "("

    :for i from=0 to=($arrLen - 1) do={
      :local item [:pick $1 $i]

      :if ([:len $strArr] > 1) do={ :set $strArr "$strArr," }
      :if ([:typeof $item] = "str") do={
        :set $strArr "$strArr$([$escapeStr $item])"
      } else={
        :set $strArr "$strArr$item"
      }
    }

    :return "$strArr)"
  }

  :local escapeValue do={
    :if ([:typeof $1] = "str") do={ :return [$escapeStr $1] }
    :if ([:typeof $1] = "array") do={ :return [$arrayToStr $1 escapeStr=$escapeStr] }
    :if ([:typeof $1] = "bool") do={:if ($1) do={ :return "yes" } else={ :return "no" }}
    :return $1
  }

  :foreach k,v in=$cont do={
    :if ([:len $v] != 0) do={
      :if ([:find $validAddArgs $k] >= 0) do={
        :set addCmd "$addCmd $k=$([$escapeValue $v convertBool=$convertBool escapeStr=$escapeStr arrayToStr=$arrayToStr])"
      } else={
        :local rk ($replaceArgs->"$k")
        :if ([:typeof $rk] != "nothing") do={ :set addCmd "$addCmd $rk=$([$escapeValue $v escapeStr=$escapeStr arrayToStr=$arrayToStr])" }
      }
    }
  }

  :execute "$addCmd" as-string
  :set contId [find where comment=$contComment]
  :if ($contId = "") do={ $abortWithMessage ("unable to add container $contComment, check add command: $addCmd") logPrefix=$logPrefix }

  :local sec 0

  :while (([get $contId]->"status") = "extracting" && $sec <= $extrTimeoutSec) do={
    :delay 1
    :set sec ($sec + 1)
  }

  :if ($sec > $extrTimeoutSec) do={ $abortWithMessage ("container $contComment extract wait timed out, something is failed or slower than expected") logPrefix=$logPrefix }
  :if ($contStarted) do={
    $logWithMessage ("Starting container $contComment") logPrefix=$logPrefix level="I"
    start $contId as-value
  }

  $logWithMessage ("Container $contComment update finished") logPrefix=$logPrefix level="I"
}

Regarding issue, could be some permissions, can you manually create and run container over API and just with script is failing?
If is not permissions issue, could be issue with payload serialization and escaping, try to log $addCmd var before :execute command (:log info $addCmd) and see if is different for same container configuration when executed from terminal and over API.
For further troubleshooting help specify if is this related to legacy API or REST API.