0

I'm trying to pass --data-raw options to a curl inside bash function, but I get option unknown error.

function api_call () {
    local data="$5"
        echo $(curl -L -X $1 "https://api.datadoghq.com/api/v1/monitor/$2" \
          -H "Accept: application/json" \
          -H "Content-Type: application/json" \
          -H "DD-API-KEY: $3" \
          -H "DD-APPLICATION-KEY: $4" \
          $data)
}

I call it with

api_call "PUT" $monitor_id $DATADOG_API_KEY $DATADOG_APP_KEY $query

my query value is

query="--data-raw '{"query":"sum(last_1m):avg:application.health{application.health:healthy,c_name:nname,!source:service-full-1} by {source}.as_count() < 60"\}')"

but it doesn't matter what I put in data, it doesn't get accepted when calling the function. It works as intended if I simply do a curl.

What am I missing? thanks!

Kurse
  • 1

1 Answers1

0

As everyone in the comments pointed out that shell splits the variable and it will not be ran as a command. Thank you @Kamil Maciorowski for the very useful links that explain this in detail. Why does my shell script choke on whitespace or other special characters? How can we run a command stored in a variable?

Kurse
  • 1