Forum Discussion
jjohnson
Nimbostratus
Jul 02, 2020iControl REST API Policy Rules
Having some trouble getting rules added to an LTM policy using iControl REST API and PowerShell. Currently I am able to get the policy into Draft status, and I can add a rule... but I am getting stuc...
jjohnson
Nimbostratus
Jul 02, 2020This does help a lot... still encountering some issues though... for the Boolean values if I send them as true of false I either get:
Invoke-RestMethod : {"code":400,"message":"Found unexpected json boolean at configuration item /ltm/policy/~Common~Drafts~TEST_POLICY_AUTOMATION/rules/Testing/conditions/equals. The json boolean is
true.","errorStack":[],"apiError":1}or
Invoke-RestMethod : {"code":400,"message":"Found unexpected json string at configuration item /ltm/policy/~Common~Drafts~TEST_POLICY_AUTOMATION/rules/Testing/conditions/equals. The json string is
\"true\".","errorStack":[],"apiError":1}This is the JSON I am using in my script, basing it off what you sent as a test
$ActionsBody = [ordered]@{
actions = @{
name = "0"
request = $true
forward = $true
pool = '/Common/pool_test'
}
conditions =@{
name = "0"
request = "true"
httpHost = "true"
equals = "true"
values = "www.mydomain.net"
}
}
Invoke-RestMethod -Uri https://$url/mgmt/tm/ltm/policy/~Common~Drafts~$Policy/rules/Testing -Method PUT -Headers $Header -Body (ConvertTo-Json $ActionsBody) -ContentType 'application/json'
- cjuniorJul 02, 2020
Nacreous
If I'm not wrong, PS writes True and False as first letter capitalized.
Try converting to a lower case string output and do not surround it with quotes.
This way works for you?
$ActionsBody = [ordered]@{ actions = @{ name = "0" request = $true forward = $true pool = '/Common/pool_test' } conditions =@{ name = "0" request = $true httpHost = $true equals = $true values = "www.mydomain.net" } } $ActionsBody |ConvertTo-JsonRegards
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
