Hi all,
I need a solution to place DNS record via WAPI.
Create is working with:
curl -k \
-u 'user:pass' \
-H 'Content-Type: application/json' \
-X POST 'https://my.ipam.com/wapi/v2.13.6/record:host' \
-d '{"ipv4addrs": [
{
"ipv4addr": "10.10.10.1"
}
],
"name": "devicename.my.network.com"}'
also updating is working with:
curl -k \
-u 'user:pass' \
-H 'Content-Type: application/json' \
-X POST 'https://my.ipam.com/wapi/v2.13.6/request' \
-d '[
{
"method": "STATE:ASSIGN",
"data": {
"host_name": "devicename.my.network.com"
}
},
{
"method": "GET",
"object": "record:host",
"data": {
"name": "##STATE:host_name:##"
},
"assign_state": {
"host_ref": "_ref"
},
"enable_substitution": true,
"discard": true
},
{
"method": "PUT",
"object": "##STATE:host_ref:##",
"enable_substitution": true,
"data": {
"ipv4addrs": [
{
"ipv4addr": "10.10.10.99"
}
]
},
"args": {
"_return_fields": "ipv4addrs"
},
"assign_state": {
"updated_ip": "ipv4addrs"
},
"discard": true
},
{
"method": "STATE:DISPLAY"
}
]'
my idea was to try updating and if it does not exist, to create the record. code for this idea:
curl -k \
-u 'user:pass' \
-H 'Content-Type: application/json' \
-X POST 'https://my.ipam.com/wapi/v2.13.6/request' \
-d '[
{
"method": "STATE:ASSIGN",
"data": {
"host_name": "devicename.my.network.com"
}
},
{
"method": "GET",
"object": "record:host",
"data": {
"name": "##STATE:host_name:##"
},
"assign_state": {
"host_ref": "_ref" //<-- Here I am getting already an error, if the object does not exist
},
"enable_substitution": true,
"discard": true
},
{
"method": "IF",
"condition": "##STATE:host_ref:##",
"then": [
{
"method": "PUT",
"object": "##STATE:host_ref:##",
"enable_substitution": true,
"data": {
"ipv4addrs": [
{
"ipv4addr": "192.168.1.100"
}
]
},
"args": {
"_return_fields": "ipv4addrs"
},
"assign_state": {
"updated_ip": "ipv4addrs"
},
"discard": true
}
],
"else": [
{
"method": "POST",
"object": "record:host",
"data": {
"name": "##STATE:host_name:##",
"ipv4addrs": [
{
"ipv4addr": "192.168.1.100"
}
]
},
"assign_state": {
"new_host_ref": "_ref"
},
"discard": true
}
]
},
{
"method": "STATE:DISPLAY"
}
]'
the error I am getting is:
{ "Error": "AdmConProtoError: The operation returned an empty list ([]) assign_state is supported only when the result operation returns a single result.",
"code": "Client.Ibap.Proto",
"text": "The operation returned an empty list ([]) assign_state is supported only when the result operation returns a single result."
} ✓
any idea how to update records in a easy way? why update doesn't create the object if it does not exist? would be much easier 😅