0

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
3
  • If I qoute it I get the error code: host-variable must be Integer, so that doesn't work either Commented Apr 13, 2021 at 7:58
  • 1
    As far as I can see, your $host is within single quotes. So it won't get expanded. Your JSON will just contain $host which is invalid. You have to do the same as you already to with $ip: replace $host by '$host' (to have $host outside of single quotes). Commented Apr 13, 2021 at 8:32
  • Solved! Thank you. Commented Apr 13, 2021 at 9:19

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.