iControl 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 stuck in the formatting for the rule actions and conditions. Does anyone know how these are supposed to be formatted?
The only examples and guidance I have been able to find don't show how to add any actions to the rules.
https://clouddocs.f5.com/api/icontrol-rest/APIRef_tm_ltm_policy.html
rules array_structure optional read/write
https://devcentral.f5.com/s/articles/icontrol-rest-cookbook-ltm-policy-ltm-policy-33300
curl -sku admin:admin https://<host>/mgmt/tm/ltm/policy/~Common~Drafts~<TestPolicy>/rules \
-X POST -H "Content-type:application/json" \
-d '{"name":"<SampleRule>", "description":"sat1" }'
The above example shows how to create a rule and give it a description, but not how to add anything to it. Any help is appreciated.
Code I have used so far for creating the Draft and Rule:
$user = "admin"
$pass = "admin"
$url = "<my f5 url>"
$header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$user"+":"+"$pass"));}
$policy = "TEST_POLICY_AUTOMATION"
$DraftBody = @{
"createDraft" = $True
}
$RulesBody = @{
"name" = "Test.API"
"description" = "I am a test"
}
### Create a draft from a policy that already exists
Invoke-RestMethod -Uri https://$url/mgmt/tm/ltm/policy/$Policy -Method PATCH -Headers $Header -Body (ConvertTo-Json $DraftBody) -ContentType "application/json"
### Attempts at modifying/adding rules to the policy in draft
### Creating the rule with name Test.API and description "I am a test" works but have been unable to add actions
Invoke-RestMethod -Uri https://$url/mgmt/tm/ltm/policy/~Common~Drafts~$Policy/rules -Method POST -Headers $Header -Body (ConvertTo-Json $RulesBody) -ContentType 'application/json'