API PUT blockedUrlCategories won't update. Comes back with not valid

SOLVED
Carlo
Here to help

API PUT blockedUrlCategories won't update. Comes back with not valid

Trying to update blockedURLCategories I followed the example at the website and I get back blockedURLCategories is not valid. this is using the put request.

If i do a get, works find.

 

{
"allowedUrlPatterns": [
"http://www.example.org",
"http://help.com.au"
],
"blockedUrlPatterns": [
"http://www.example.com",
"http://www.betting.com"
],
"blockedUrlCategories": [
{
"id": "meraki:contentFiltering/category/1",
"name":"Real Estate"
},
{
"id":"meraki:contentFiltering/category/7",
"name":"Shopping"
}
],
"urlCategoryListSize": "topSites"
}

1 ACCEPTED SOLUTION
CBurkhead
Building a reputation

I had this problem too, and once I removed the category names, it worked fine. I suspect they did it this way so that you could not possibly change a category name associated with a particular ID. Some documentation about this would have been nice.

View solution in original post

9 REPLIES 9
BrechtSchamp
Kind of a big deal

I have the same behavior. Feels like a bug.

 

If you take away the contents of blockedUrlCategories it works:

{
	"allowedUrlPatterns": [
		"http://www.example.org",
		"http://help.com.au"
	],
	"blockedUrlPatterns": [
		"http://www.example.com",
		"http://www.betting.com"
	],
	"blockedUrlCategories": [],
	"urlCategoryListSize": "topSites"
}

I have the same issue - we need to have these category APIs fixed so we don't have to go through hundreds of sites to block specific categories.  Also, this applies to blocked countries as well - the support answer of "make a wish" doesn't really seem reasonable here.

 

Hello All,

 

Just been testing this and is working ok Json is in the following format no name details and a list of all the categories you require.

 

"blockedUrlCategories": [

"meraki:contentFiltering/category/11",
"meraki:contentFiltering/category/18",
"meraki:contentFiltering/category/25",
"meraki:contentFiltering/category/27",
"meraki:contentFiltering/category/33",
"meraki:contentFiltering/category/34",
"meraki:contentFiltering/category/46",
"meraki:contentFiltering/category/48",
"meraki:contentFiltering/category/49",
"meraki:contentFiltering/category/53",
"meraki:contentFiltering/category/54",
"meraki:contentFiltering/category/56",
"meraki:contentFiltering/category/57",
"meraki:contentFiltering/category/59",
"meraki:contentFiltering/category/62",
"meraki:contentFiltering/category/64",
"meraki:contentFiltering/category/67",
"meraki:contentFiltering/category/70"

]

 

hope it helps

CBurkhead
Building a reputation

I had this problem too, and once I removed the category names, it worked fine. I suspect they did it this way so that you could not possibly change a category name associated with a particular ID. Some documentation about this would have been nice.

Still not working for me. All the below iterations gives me "Bad request: There was a problem in the JSON you submitted"

 

"blockedUrlCategories": [
{
"id": "meraki:contentFiltering/category/11",
}
],

 

and

 

"blockedUrlCategories": [
{
"meraki:contentFiltering/category/11",
}
],

 

and

 

"blockedUrlCategories": [
{
"id": "meraki:contentFiltering/category/11",
}
],

 

and

 

"blockedUrlCategories": [
"meraki:contentFiltering/category/11",
],

 

Only one that works is to omit the category to blank:

 

"blockedUrlCategories": [],

 

Can someone print their entire json so that i can copy and paste into mine?

 

 

If you are using 1 category there should be no comma "," at the end of the line then denotes more to action.

 

"blockedUrlCategories": [

"meraki:contentFiltering/category/11"

]

I'll just put on my dunce cap and sit in this corner over here. Thanks for the speedy reply.

Hi Guys,

 

I think I'm running into this too. Big disclaimer here, I'm no expert on programming, so excuse the crudeness if I'm doing something wrong here. I am working on a script that will allow me to specify a site to clone the content filtering rules. I just made the same script for the L7 rules and it worked perfectly. This one is not working so well. Below is the script I'm using right now. I'm just trying to collect the content filtering rules, which comes in as a hashtable of hashtables I believe. I am then converting it to a JSON, which I thought turned it into a string.

 

When I try to run the single Invoke-RestMethod, at the bottom, to put the JSON rules at another site I get an Error (400) Bad Request. I used the Streamer method to try to troubleshoot. That tells me the following 

 

{Each element in 'blockedUrlCategories' must be a string}

 

I can't understand why that would be the case. If I do a GetType() on my $json it shows that name is string but the basetype is system.object. I'm not sure what I'm missing here. Do I have to do something to the JSON data to change it to a string?

 

IsPublic      IsSerial         Name         BaseType
--------           --------          ----                 --------
True           True              String         System.Object

 

 

 

#create header with API key
Write-host "Creating API Key Header"
$header_org = @{
    "X-Cisco-Meraki-API-Key" = $api_key
    "Content-Type" = 'application/json'
    }


#######################################################
# Get list of all the network ID's in the org
##################################################

#create meraki uri to list the networks in the org
$MerakiUri = $baseuri + "/organizations/$org_id/networks"

#execute rest call
Write-host "Collecting all network ID's in the organization"
$networklist = Invoke-RestMethod -Method Get -Uri $MerakiUri  -Headers $header_org

#create empty array to store network ID's for each site
$networkArray = $null
$networkArray = @()

#put networks into an array using the list we got from the REST API call
foreach($network in $networklist){
    $networkArray = [array]($networkArray + $network.id | where-object{$_ -notlike "$network_id"})
    }

###############################################################
# Get the L7 geoblocking countries out of site we are cloning #
###############################################################


#create merakiuri to list the L7 rules in the network
$MerakiUri = $baseuri + "/networks/$network_id/contentFiltering"

#execute rest call to get the config for the site to clone
write-host "Collecting Content Filtering FW rules from $network_id"
$tempcontentrules = Invoke-RestMethod -Method Get -Uri $MerakiUri  -Headers $header_org

#drop the name property from the blockedurlcategories. Found this in the forums to resolve error wtih API put
$tempcontentrules.blockedUrlCategories = $tempcontentrules.blockedUrlCategories | Select-Object -Property * -ExcludeProperty 'name'

#convert rules to json format
Write-host "converting rules into JSON format"
$contentrules_json = ConvertTo-Json -Depth 100 -InputObject $tempcontentrules


###############################################################
# Put the content filters onto the rest of the sites          #
###############################################################

foreach ($each_network_id in $networkArray){

#create URI for contentfiltering rule put
$content_uri = $baseuri + "/networks/$each_network_id/contentFiltering"

#add rule
write-host "Creating content rules for network $each_network_id"
Invoke-RestMethod -Method Put -Uri $content_uri -MaximumRedirection 0 -Headers $header_org -Body $contentrules_json

    }

 

Try replacing your line:

$tempcontentrules.blockedUrlCategories = $tempcontentrules.blockedUrlCategories | Select-Object -Property * -ExcludeProperty 'name'

 with this:

$tempcontentrules.blockedUrlCategories = $($tempcontentrules.blockedUrlCategories | Select-Object -Property * -ExcludeProperty 'name').id

The first line stores the following in your $tempcontentrules.blockedUrlCategories variable:

"blockedUrlCategories": [
    {
      "id": "meraki:contentFiltering/category/11"
    },
    {
      "id": "meraki:contentFiltering/category/46"
    },
    {
      "id": "meraki:contentFiltering/category/49"
    },
    {
      "id": "meraki:contentFiltering/category/52"
    },
    {
      "id": "meraki:contentFiltering/category/56"
    },
    {
      "id": "meraki:contentFiltering/category/57"
    },
    {
      "id": "meraki:contentFiltering/category/59"
    },
    {
      "id": "meraki:contentFiltering/category/70"
    },
    {
      "id": "meraki:contentFiltering/category/71"
    }
  ],

Meraki doesn't accept the "id": part of that json, so by using the second line you get this instead:

  "blockedUrlCategories": [
    "meraki:contentFiltering/category/11",
    "meraki:contentFiltering/category/46",
    "meraki:contentFiltering/category/49",
    "meraki:contentFiltering/category/52",
    "meraki:contentFiltering/category/56",
    "meraki:contentFiltering/category/57",
    "meraki:contentFiltering/category/59",
    "meraki:contentFiltering/category/70",
    "meraki:contentFiltering/category/71"
  ],

 
Literally just had to figure all this out with the help of this thread!

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.