Hi and thanks for your help. I try to pass pair of arguments in a curl command. I already found out how to pass single variables, like my MetricType, MetricName, current time and the value from $1.
I can pass both the Dim1Name AND the value, like this:
curl --header "Content-Type: application/json"
--header "X-SF-TOKEN: ${TOKEN}" -X POST -i https://URL/datapoint
--data '{"'"${MetricType}"'": [{ "metric": "'"${MetricName}"'","value": 300,
"dimensions": {"'"${Dim1Name}"'": "'"${Dim1Value}"'"}
}]}'
What I'd like to achieve is something like this, where DimOption=Dim1Name: Dim1Value so the code would look like this (but the Name and Value need quotes). Is it possible ? (And with a coma as well in case I want to send 2+ pairs of arguments)
curl --header "Content-Type: application/json"
--header "X-SF-TOKEN: ${TOKEN}" -X POST -i https://URL/datapoint
--data '{"'"${MetricType}"'": [{ "metric": "'"${MetricName}"'","value": 300,
"dimensions": {"'"${DimOption}'""}
}]}'
You can use a multi-line script for easier handling of the body and without worry about the quotes scape:
send.sh
data=$(cat data.json)
new_data=${data/@name/jane}
new_data=${new_data/@last_name/doe}
curl localhost:8080/foo -d "$new_data" -H "Content-Type: application/json"
echo
data.json
{
"hello": "@name @last_name"
}
result
Explanation