Showing results for 
Search instead for 
Did you mean: 

Cisco Community Designated VIP Class of 2020


FMC PreFilter via API (fmcapi)


I'm not a developer but I wan't to automate some tasks for my client.

We have a FMC and I triy to create a PreFilter for all GRE Tunnels. So I downloaded the fmcapi. In general all things work fine. I can create objects and access rules. But if I try to create a PreFilter I get an unkown error.

My Code looks like:


# Import FMC API
import fmcapi

# Define config file
cfgfile = 'test.cfg'

# Read the config file for settings
cfg = configparser.ConfigParser()

# Create FMC object
with fmcapi.FMC(host = cfg['FMC']['host'], username = cfg['FMC']['user'], password = cfg['FMC']['passwd'], autodeploy = False, file_logging = scriptlog)  as mstfmc:

# Create PreFilter Object prefilter_rule = fmcapi.PreFilterRules(fmc=mstfmc, prefilter_name=cfg['FMC']['prefilter']) # Set the PreFilter Values = "Tunnel920" prefilter_rule.enabled = True prefilter_rule.rule_type = "TUNNEL" prefilter_rule.source_interface(action="add", name="inside_muenchenstein") prefilter_rule.destination_interface(action="add", name="outside_muenchenstein") prefilter_rule.action = "FASTPATH" prefilter_rule.destination_port(action="add", literal={"protocol": "47"}) # Post the Values to the FMC

And the log output looks like:



2020/01/02-12:12:35 - - Requesting new tokens from https://fmcurl/api/fmc_platform/v1/auth/generatetoken.
2020/01/02-12:12:39 - - Building base to URLs.
2020/01/02-12:12:39 - - Populating vdbVersion, sruVersion, serverVersion, and geoVersion FMC instance variables.
2020/01/02-12:12:39 - - This FMC's version is (build 57)
2020/01/02-12:12:39 - - Searching ID for prefilter "default_sdag_prefilter"
2020/01/02-12:12:40 - - GET success. Object with name: "default_sdag_prefilter" and id: "005056BE-875A-0ed3-0000-012884903880" fetched from FMC.
2020/01/02-12:12:40 - - GET success. Object with name: "inside_muenchenstein" and id: "2e2333ea-2b9c-11ea-adf4-be47e6928388" fetched from FMC.
2020/01/02-12:12:41 - - GET success. Object with name: "outside_muenchenstein" and id: "21587c74-2b9c-11ea-adf4-be47e6928388" fetched from FMC.
2020/01/02-12:12:49 - - Error in POST operation --> 400 Client Error: Bad Request for url: https://fmcurl/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f/policy/prefilterpolicies/005056BE-875A-0ed3-0000-012884903880/prefilterrules
2020/01/02-12:12:49 - - json_response -->	{'error': {'category': 'FRAMEWORK', 'messages': [{}], 'severity': 'ERROR'}}
2020/01/02-12:12:49 - - POST failure.  No data in API response.
2020/01/02-12:12:49 - - Auto deploy changes set to False.  Use the Deploy button in FMC to push changes to FTDs.



Can you help me, how to create a PreFilter Rule like this:


PreFilter Example.PNG


Thanks a lot for any help.


Best Regards,


Everyone's tags (3)
CreatePlease to create content
Content for Community-Ad
FusionCharts will render here