I am using an API and I'm not able to bind an Integer Variable into it. I will attach my script below, but a little explanation can't hurt: Another script filters data that is send via curl, most of this data are strings, but the API forces this one to be Integer.
curl \
--data '{"version":"2.0",
"method":"cmdb.object.create",
"params":{"type":"C__OBJTYPE__VIRTUAL_SERVER",
"title":"'"${name}"'",
"categories":{"C__CATG__IP": [ { "ipv4_address" : "'"${ip}"'" } ],
"C__CATG__VIRTUAL_MACHINE__ROOT": [ { "hosts": $host, "description" : "'"${ops}"'" } ]
},
"apikey":"apikey"},"id": 1 }' \
--header "Content-Type: application/json" \
https://someURL
Where name could be "VirtualMachine1", ipv4_address "1.2.3.4", host 736, ops "Windows 7".
The error code with this curl is: code":-32600,"message":"Invalid request : Provided request is not a valid json rpc."
It works if I just write a number instead of $host so I guess I just bind the variable wrong.
A valid and working request would be:
curl \
--data '{"version":"2.0",
"method":"cmdb.object.create",
"params":{"type":"C__OBJTYPE__VIRTUAL_SERVER",
"title":"'"${name}"'",
"categories":{"C__CATG__IP": [ { "ipv4_address" : "'"${ip}"'" } ],
"C__CATG__VIRTUAL_MACHINE__ROOT": [ { "hosts": 123, "description" : "'"${ops}"'" } ]
},
"apikey":"apikey"},"id": 1 }' \
--header "Content-Type: application/json" \
https://someURL
$hostis within single quotes. So it won't get expanded. Your JSON will just contain$hostwhich is invalid. You have to do the same as you already to with$ip: replace$hostby'$host'(to have$hostoutside of single quotes).