Returning patterns for policy rules with new Okta sdk version 7

Hello,
we have previously been using the Okta client to retrieve policy rules and iterate over them to get userIdentifier and patterns like this:

var policy = await OktaClient.GetAsync<Policy>($"/api/v1/policies/{policyId}?expand=rules");
var rules = await policy.ListPolicyRules().ToListAsync();

The OktaClient is no longer present in version 7. I found this method instead, but it doesn’t return userIdentifier and patterns as before:

var rules = PolicyApi.ListPolicyRules(policyId);

How can we retrieve the same data as in version 5?

I’ve tried new api clients, but the policy rule in version 7 has far less data than before.

Thank you.

Hello, @Ondrej

In Okta SDK version 7, the approach to retrieve policy rules along with their details like userIdentifier and patterns has changed. The OktaClient class and its methods you were using are no longer available. Instead, you can use the Policy API directly to get the policy and its rules. Here’s an updated way to retrieve the same data:

// Assuming you have set up your Okta client configuration
var oktaClient = new OktaClient(new OktaClientConfiguration
{
OktaDomain = “https://{yourOktaDomain}”,
Token = “{apiToken}”
});

// Get a policy along with its rules
var policy = await oktaClient.Policies.GetPolicyAsync(policyId, “expand=rules”);

// List all policy rules
var rules = await policy.ListPolicyRules(oktaClient).ToListAsync();

// Iterate over the rules to get userIdentifier and patterns
foreach (var rule in rules)
{
var userIdentifier = rule.Conditions.People.Users;
var patterns = rule.Conditions.People.Groups;
// Process the userIdentifier and patterns as needed
}

This code uses the GetPolicyAsync method with the expand=rules parameter to retrieve the policy and its associated rules. The ListPolicyRules method is then used to list all the rules for that policy. You can access the userIdentifier and patterns through the Conditions property of each rule.

Please replace {yourOktaDomain} and {apiToken} with your actual Okta domain and API token. Also, ensure that you have the necessary permissions to access the policy information.

Best Regard,
ryan1969

Hello @ryan1969, thank you for your response, but the OktaClient class is removed in the latest version so I can’t use this one right? I don’t get the rule’s patterns in the PolicyApi response.