cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3253
Views
0
Helpful
5
Replies

Adding group with members through FMC API

Garfield
Level 1
Level 1

Hey everyone,

I'm creating a script that adds hosts and groups to FMC, however it seems that when you want to add hosts to a group you need the unique id for that host and not only the name for the host. Which is a bit of a nightmare as you need to collect the id for this first.

Can someone confirm this?

Thanks

Stijn

5 Replies 5

neipatel
Cisco Employee
Cisco Employee
That is correct, everything in the API is referenced by a unique GUID. When creating a new host the API response will return the GUID for the newly created host which can then be used to add it to a new group. For existing hosts you can run a call to GET all hosts and then iterate over the response looking for the name and pull the GUID for that name, and then use it to add to a group.

Today this is the only way it can be done.

Ok thanks for the reply, the only problem with a GET for all hosts is that the reply is paged.

So the script needs to send GETs for every page. Need to figure out how to do that.

But thank you for confirming.

I am working on this right now too and you can set a limit on the number of returned objects. Below is what I did in my script.

https://$fmcIP//api/fmc_config/v1/domain/$fpGlobal/object/networkaddresses?limit=1000

That would indeed be a possibility, but it's not very durable. Our environment will easily surpass 1000 hosts. To be honest, collecting 1000 hosts to update 1 is not a great use of resources.

However I have noticed something, apparently when you try to push an already existing object it will obviously throw an error but it will also return the object id in the return message.

If that is correct then you could first try to push an object and just collect the objectid like that.

Maybe neipatel could confirm that this is a possibility?

Thanks

Stijn 

I don't know if you've found a good solution for this, but I'm currently making some headway here.  In the initial GET of a collection, one of the collections returned is "paging", which contains the URL for the next page.  I have found that it is trivial to capture that URL and then iterate over the collection in that manner.  I can provide a code example, if it's helpful!

 

HTH,

Colin

Review Cisco Networking for a $25 gift card