Introducing SOC Insights for BloxOne Threat Defense: Boost your SOC efficiency with AI-driven insights to eliminate manual work and accelerate investigation and response times. Read the blog announcement here.

API Examples

Reply

Infoblox WAPI for performing following tasks !!

Not applicable
Posts: 2
51100     0

Hi All,

I have to do the following task using the WAPI , any assistance will be great !

1>Create a DNS entries 

2>Remove DNS entries

3>Assign DNS name to IP 

4>Remove Server from DNS

 

Do we have WAPI's function for these ??

 

 

Re: The definitive list of REST examples

Guru
Posts: 26
51100     0

I'm using python with the WAPI, and cannot find a means of importing an ISC dhcpd.leases fileas part of a migration.  It apears that the method import_data is not supported in the InfobloxAPI.py file.  Is there another file I need to import?  My call looks as follows:

def apiImportLeases(path):
    i = InfobloxAPI(type='test',verbose=True,object='session',method='import_data')
    data = {'type': 'leases','format': 'ISC', 'path': path,'lease_precedence': 'newest'}
    i.data = data
    i.username = un
    i.password = pw
    r = i.run()
    return r

The response I get is:

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    apiImportLeases('/Users/Defitz/Downloads/dhcpd/dhcpd.leases_wss-1')
  File "<pyshell#4>", line 2, in apiImportLeases
    i = InfobloxAPI(type='test',verbose=True,object='session',method='import_data')
  File "/Users/Defitz/Documents/InfobloxAPI.py", line 55, in __init__
    raise Exception(self.method + " is not a valid method")
Exception: IMPORT_DATA is not a valid method

Re: The definitive list of REST examples

New Member
Posts: 1
51100     0

quick question here about doing a search on an array field.  In particular I'd like to search for ipv4address objects with a specific name in the names field.  The wapi documentation says that this field is searchable and is of type string array.  How does one go about searching a string array from the rest commands.  For instance, to search by ip_address this works:

 

"https://gm.example.com/wapi/v2.2/ipv4address?ip_address=10.10.10.10"

 

but this does not:

 

"https://gm.example.com/wapi/v2.2/ipv4address?names=servername.example.com"

Re: The definitive list of REST examples

Adviser
Posts: 3
51100     0

The ipv4address object requires searching on an ip address.  If you include an ip address you can also search on name(s).

 

E.g.,

 

"https://gm.example.com/wapi/v2.2/ipv4address?ip_address=10.10.10.10&names=servername.example.com"

 

will work, but not 

 

"https://gm.example.com/wapi/v2.2/ipv4address?names=servername.example.com"

 

To search on a name, try using the allrecords object instead.

 

E.g. 

 

"https://gm.example.com/wapi/v2.2/allrecords?zone=example.com&name=servername&_return_fields%2b=addre...

 

You can also use the new object body request we added in WAPI 2.1/NIOS 7.1 to search for names across multiple objects at once.  

 

E.g.

 

curl -k1 -u admin -H "Content-Type: application/json" -X POST https://gm.example.com/wapi/v2.2/request -d '

[

   {

       "method": "GET",

       "object": "record:host",

       "data": {"name":"servername.example.com"},

       "args": {"_return_fields":"name,dns_name,aliases,dns_aliases,ipv4addrs,configure_for_dns"}

},

   {

       "method": "GET",

       "object": "record:a",

       "data": {"name":"servername.example.com"},

       "args": {}

},

{

       "method": "GET",

       "object": "record:cname",

       "data": {"name":"servername.example.com"},

       "args": {}

}

]'

Create Extensible Attributes via an API?

[ Edited ]
New Member
Posts: 1
51100     0

Hello All, 

 

This list is awsesome and it has been so helpful in our automation.

 

I am at a point where we are trying to use the extattrs to track addtional meta data. I am able to populate the various extattrs just fine in a POST to /record:host, but the attributes MUST already exist.

 

Is there an API that can be used to create additional attributes? Since the extattrs could be considered a "requirement" for our services automation, we would like to automatically create them if they do not already exist.

Re: Create Extensible Attributes via an API?

Adviser
Posts: 3
51100     0

Glad to hear that the examples have been helpful.  

 

If you have ideas or suggestions for other examples you'd like to see, please post them to the forum so we can keep adding to them.

 

In NIOS 7.2/WAPI 2.2 we added support for creating/modifying extensible attribute definitions via WAPI.

 

Example:

 

curl -k1 -u ibuser -X POST 'https://[gridmaster]/wapi/v2.2/extensibleattributedef' -H "Content-Type:application/json" -d '{"name":"TestEA","type":"STRING"}'

 

[do delete]

[ Edited ]
Techie
Posts: 2
51100     0

sorry, wrong topic. please delete entry.

Re: The definitive list of REST examples: Returning all A records from the external view

New Member
Posts: 3
51100     0

Not sure if this is the correct place to post this however.

 

Returning all A records from the external view.

 

I have been seconded to a customer’s where the environment is tightly controlled and one of the tasks I have been asked to look at while here is to collect a list of all external DNS records from all their external facing DNS zones of which they have 10,000s.

 

Access to their Grid is read only and I am working from a heavily locked down laptop. Anyway I have been able to load Firefox and the Restclient Add-on onto the machine I am working on.

 

I have managed to return the following but when increasing the number of results returned get an error regarding the result set being too large.

 

https://HOST/wapi/v1.4.2/record:a?_return_type=xml-pretty&view=external&_max_results=20000

 

I was hoping to filter the results by ipv4addr and the first two octets of the addresses or perhaps using a not to exclude some of the large number of defensive domains that all refer to the same IP Address so have tried including ipv4addr~=208.67 (and several variations on this) and also ipv4addr!=208.67.220.220

 

Any suggestion would be appreciated.

Re: The definitive list of REST examples: Returning all A records from the external view

Adviser
Posts: 8
51100     0

Do a zone transfer. much faster and easier.

Re: The definitive list of REST examples: Returning all A records from the external view

New Member
Posts: 3
51100     0

Hi,

 

Thanks for the suggestion. We did considered doing a zone transfer of the main reverse zone in which all the PTRs for the public addresses should sit. However the configuration on the Grid has been populated over a number of years by different admins and there is no guarentee that PTRs have been created for all A and Host Records. Which is why I am looking at using the WAPi to  retrieve the Information.

 

Regards

 

Dan

Re: The definitive list of REST examples: Returning all A records from the external view

New Member
Posts: 3
51100     0

Found was able to retrieve the information required using https://10.31.2.20/wapi/v1.4.2/record:a?_return_type=xml-pretty&view=external&_max_results=20000 and the FF restclient. It kept generating a script error in FF but if you ended the script the data required was returned.

 

The repeated for host records.

 

Regards

 

Dan


Re: The definitive list of REST examples

New Member
Posts: 2
51100     0

This does help a lot.

 

Is there a common method for returning values to a default setting?

 

I have a zone that has overridden the GM values for the allow_transfer ACL. I would like to return this setting to the default value that inherits the GM setting.

 

Thanks

 

 

 

Re: The definitive list of REST examples

New Member
Posts: 2
51100     0

I answered my own question : the "use_" structure...

 

example:

 

curl -k1 -u adminSmiley Tongueasswd -H "Content-Type: application/json" -X PUT https://gridmaster/wapi/v2.2/zone_auth/klkl5zLnpvbmUkLl9kerTTr55NvbS50cmFuc3F1ZXN0:zonename.com/default -d '{"use_allow_transfer":false}'

 

 

 

Re: The definitive list of REST examples

[ Edited ]
New Member
Posts: 1
51100     0

Going to add some examples i found hard to come by when trying to script additons to host or fixedaddress using variables, you need to use a double set of "" Smiley Sad

Using Powershell for this. 

 

When using :

wapi/v2.2/record:host

Your Json query should resemble:

"{""ipv4addrs"":[{""ipv4addr"":""$the_ip_you_want_to_use""}],""name"":""$your_server"",""configure_for_dns"":false}"

 

When Using:

wapi/v2.2/fixedaddress

 

Your JSON query should resemble:

"{""ipv4addr"":""$the_ip_you_want_to_use"",""mac"":""00:00:00:00:00:00"",""name"":""$your_server""}"

Or

"{""ipv4addr"":""func:nextavailableip:10.10.10.0/24"",""mac"":""00:00:00:00:00:00"",""name"":""$your_server""}"

Re: The definitive list of REST examples

[ Edited ]
New Member
Posts: 1
51100     0

Hoping someone can help - anyway I can use the API to retrieve the available OR used IP space in a DHCP range?  Either value works.

Re: The definitive list of REST examples

New Member
Posts: 1
51100     0

Is it possible to reclaim an IP with rest?  If so,  can I see an example?

Re: The definitive list of REST examples

New Member
Posts: 2
51100     0

Hi, thanks very much for the overview.

 

I was wondering if there is a way to retrieve all the extensible attributes from InfoBlox?

 

We've created a few extensible attributes as a list that contain our network sites and countries. I would like to be able to retrieve (and possibly even edit) all configured list values through the API. Looking at the API documentation there doesn't seem to be a REST object for this so would require us to retrieve all objects and extract the data from there.

 

Regards,

Matt

Re: infoblox WAPI and .Net integration

Adviser
Posts: 175
51100     0

This is an extremely popular topic and thread so we're highlighting it throughout the site.  Here is an additional thread with further info.  We'll consider merging them, but the topics are slightly different.

 

https://community.infoblox.com/t5/API-Integration/The-definitive-list-of-REST-examples/td-p/1214/pag...

 

#WeGotYourBack

 

Eric

If you appreciate my efforts, please give me a kudo ↓ or Accept as solution to help others find it faster.

Re: infoblox WAPI and .Net integration

Adviser
Posts: 175
51100     0

This is an extremely popular topic and thread so we're highlighting it throughout the site.  Here is an additional thread with further info.  We'll consider merging them, but the topics are slightly different.

 

https://community.infoblox.com/t5/API-Integration/The-definitive-list-of-REST-examples/td-p/1214/pag...

 

#WeGotYourBack

 

Eric

If you appreciate my efforts, please give me a kudo ↓ or Accept as solution to help others find it faster.

Re: Removing a host record

New Member
Posts: 2
51100     0

Hi, I"m new to infoblox. Our company just uses it for reserving IP addresses. We create IPv4 reservations that is just used for tracking. It is not linked to DNS so there is no mac address in the reservations that we create. In the rest call, is the mac mandatory? How would I use the API to remove the reservation?

Re: Use ipv4addrs+ to add one or more IP addresses to host record

New Member
Posts: 2
51100     0

Is this the same as removing a ipv4 reservation or is that a different object?

 

Finally, note that you can also use the field name 'ipv4addrs-' to remove one or more IP addresses for that host; for example, the following code would remove all the IP addresses added above:

request_data = {'ipv4addrs-': [{'ipv4addr': '192.168.201.16'},
                               {'ipv4addr': '192.168.201.17'},
                               {'ipv4addr': '192.168.201.18'}]}
r = requests.put('https://gm.example.com/wapi/v1.0/' + host_ref,
                  data=json.dumps(request_data),
                  auth=('admin', 'infoblox'))

 

Re: infoblox WAPI and .Net integration

Adviser
Posts: 7
51101     0

I haven't seen any .NET specific examples but there may be some on Github posted by other customers.  There are a few repositories that provide some examples using PowerShell that may help lead you down the right path as well.  There's even a post (by me) regarding one of the PowerShell repositories here.

 

https://community.infoblox.com/t5/API-Integration/Powershell-Infoblox-ps1/m-p/1150#M197

 

Re: Removing a host record

[ Edited ]
New Member
Posts: 1
51101     0

For those of you using PowerShell, here's how to "reclaim" an IP address regardless of what type of record is assigned to it.  I hope this helps someone.

 

$ip = "10.10.5.100"
$Credential = Get-Credential
$InfobloxURI = "https://infobloxserver/wapi/v1.3/ipv4address?ip_address=$ip"
$ips = Invoke-RestMethod -Method GET $InfobloxURI -Credential $Credential
$objects = $ips.objects
foreach ($object in $objects)
{
    $InfobloxURI = "https://infobloxserver/wapi/v1.3/$object"
    Invoke-RestMethod -Method DELETE $InfobloxURI -Credential $Credential
}

 

Don't forget to replace "infobloxserver" in the URI with the name or IP address of your Infoblox Grid Master.

Re: The definitive list of REST examples

New Member
Posts: 2
51101     0

Is there an option to add a host without adding it to DNS? Our appliance is not currently authoritative for the fqdn but we want to use it as an IP manager.

 

I get

Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    resp2=x.create_host_record(newip,'testauto.mydomain.com')
  File "C:/Python27/projects/ibx/src/apitest.py", line 107, in create_host_record
    raise InfobloxGeneralException(r_json['text'])
InfobloxGeneralException: Cannot add records to a zone that is not authoritative

 

Thanks.

Re: The definitive list of REST examples

New Member
Posts: 2
51101     0

Hi tgraham2,

 

If you use the record:host object and set 'configure_for_dns' to False you are able to create a static host record in InfoBlox. Here's some (untested) python code that should help you out.

 

import requests

host = 'infoblox.yourdomain.com'
api_version = 'v2.3'
url = "https://{}/wapi{}/record:host".format(host, api_version)

ip_addresses = [
  {
    'ipv4addr': '10.0.0.1'
  }
]

payload = {
    'configure_for_dns': False,
    'name': 'MyFirstStaticHost',
    'ipv4addrs': ip_addresses,
}

requests.post(url, data=json.dumps(payload))

 

Regards,

Thiezn

Re: The definitive list of REST examples

Adviser
Posts: 7
51101     0
Another option is to create a zone (.local or ipam.local or whatever works for you) and add the host object there. This provides another mechanism for finding all hosts in one area. Hosts without DNS entries are scattered in the subnets they are defined in. Using a zone that you create for this purpose would provide you with a consistent location to find them.

When you define the zone, you would create it as an authoritative zone but you could choose to disable it or even just create it without assigning it to any DNS members.

Re: The definitive list of REST examples

New Member
Posts: 1
51101     0

Hello together,

 

i am having some problems creating A-records via WAPI and I hope someone might help me.

 

My REST Call looks like this:

POST https://some.host/wapi/v2.3/record:a

Content Type is set to "application/json"

 

My JSON looks like this:

{
    "ipv4addrs": "1.2.3.4",
    "name": "host.domain.com"
}

 

(Obviously the values are changed but the setup should be the same)

 

I always get a "400 - Bad Request" return and I don't know why.

 

I tried to enter the view name too, but that didn't change a thing (the view I entered is the default view, namely 'Microsoft').

 

I'd appreciate if someone could help me, I'm running out of ideas.

 

Thanks in advance and best regards,

Patrick

Re: Use ipv4addrs+ to add one or more IP addresses to host record

Techie
Posts: 5
51101     0

Hi, 

 

I try the first part of your code, as follows (using python 3.4):


import requests
import sys
import json

 

request_params = {'name': 'fred14.domain-here'}
r = requests.get('https://10.26.77.230/wapi/v1.0/record:host',
      verify=False,
      params=request_params,
      auth=('username-here','password-here'))
host_ref = r.json()[0]['_ref']

 

and I get this error:

 

Traceback (most recent call last):
File "./chassis.py", line 13, in <module>
host_ref = r.json()[0]['_ref']
IndexError: list index out of range

 

I think it's complaining about '_ref' not being a valid numerical index.  What's intent and goal of putting '_ref' there?

 

I know that's a valid record, as if I query with nslookup, I get:

 

$ nslookup fred14.aw.domain-here
~ │10.26.77.230
~ │Server: 10.26.77.230
~ │Address: 10.26.77.230#53
~ │
~ │Name: fred14.aw.domain-here
~ │Address: 10.223.2.1

 

I also see the same thing in the Infoblox GUI. 

 

It seems there isn't anything pulled in the request from the grid master.  When I change the last three lines to the following:

 

host_ref = r.json()
print(dir(host_ref))
print(host_ref)

 

and run it, I get this:

 

['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
[]

 

But again, this doesn't make sense; I should see the same as what I'm seeing in nslookup as well as the Infoblox GUI.  Anybody have thoughts on what I'm missing?

Re: Use ipv4addrs+ to add one or more IP addresses to host record

Techie
Posts: 5
51101     0

Hi, 

 

I try the first part of your code, as follows (using python 3.4):


import requests
import sys
import json

 

request_params = {'name': 'fred14.domain-here'}
r = requests.get('https://10.26.77.230/wapi/v1.0/record:host',
      verify=False,
      params=request_params,
      auth=('username-here','password-here'))
host_ref = r.json()[0]['_ref']

 

and I get this error:

 

Traceback (most recent call last):
File "./chassis.py", line 13, in <module>
host_ref = r.json()[0]['_ref']
IndexError: list index out of range

 

I think it's complaining about '_ref' not being a valid numerical index.  What's intent and goal of putting '_ref' there?

 

I know that's a valid record, as if I query with nslookup, I get:

 

$ nslookup fred14.aw.domain-here
~ │10.26.77.230
~ │Server: 10.26.77.230
~ │Address: 10.26.77.230#53
~ │
~ │Name: fred14.aw.domain-here
~ │Address: 10.223.2.1

 

I also see the same thing in the Infoblox GUI. 

 

It seems there isn't anything pulled in the request from the grid master.  When I change the last three lines to the following:

 

host_ref = r.json()
print(dir(host_ref))
print(host_ref)

 

and run it, I get this:

 

['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
[]

 

But again, this doesn't make sense; I should see the same as what I'm seeing in nslookup as well as the Infoblox GUI.  Anybody have thoughts on what I'm missing?

Re: The definitive list of REST examples

Adviser
Posts: 11
51101     0

 

Patrick-

 

Your problem is a simple typo in your JSON.  The record:a object expects an "ipv4addr" (singular) parameter, not "ipv4addrs" (plural). It's an easy mistake to make because record:host does actually use "ipv4addrs" (plural).

Showing results for 
Search instead for 
Did you mean: 

Recommended for You