blog-aug-5.jpg

Create, Search and Delete a Host Object Using the REST API

 

There has been a great deal of interest in the new NIOS REST based API and we have had tons of questions about how it works. One common request is how to work with the host object via the new API. Here are some basic examples on how to create, search for and delete a host via the REST API:

Create a host:

curl -k -u admin:infoblox -H "Content-Type: application/json" -X POST https://10.65.16.12/wapi/v1.0/record:host -d '{ "ipv4addrs":[{"configure_for_dhcp": false,"ipv4addr": "10.10.10.12"}],"name": "newhost.bloxdemo.com","view": "default"}'

 

Search for the host that was just created:

 

curl -k -u admin:infoblox -X GET https://10.65.16.12/wapi/v1.0/record:host -d name~=newhost

 

The search returns a reference (_ref) for the host:

 

[
    {
        "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5ibG94ZGVtby5uZXdob3N0:newhost.bloxdemo.com/default", 
        "ipv4addrs": [
            {
                "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLmJsb3hkZW1vLm5ld2hvc3QuMTAuMTAuMTAuMTIu:10.10.10.12/newhost.bloxdemo.com/default", 
                "configure_for_dhcp": false, 
                "host": "newhost.bloxdemo.com", 
                "ipv4addr": "10.10.10.12"
            }
        ], 
        "name": "newhost.bloxdemo.com", 
        "view": "default"
    }
]

 

Delete the host using the reference:

 

curl -k -u admin:infoblox -X DELETE https://10.65.16.12/wapi/v1.0/record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5ibG94ZGVtby5uZXdob3N0

 

Comments
‎02-13-2015 01:13 PM
How do you add/delete an Alias using curl?
‎07-22-2015 01:24 AM

I have the same question...I just keep getting errors while creating/deleting aliases for host objects.

"List value expected for field: aliases" , but if I use the same syntax for aliases as I do for ipv4addrs I get this error:

"Elements of field \"aliases\" must be strings""

 

//EDIT: nevermind, I fixed my problem, but I'm using cURL with PHP

Adviser
‎09-29-2015 02:33 PM

DSchmalen, can you share with others so they know how you resolved it?

Authority
‎11-15-2016 01:24 PM

As easy as it gets! Great primer. Thank you. 

Showing results for 
Search instead for 
Did you mean: