cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
abaligetig
Regular Visitor

Setting PBI report policies with .Net OData client

Hi!

 

In our company we have a lot of reports with a dozens of users, therefore we would like to automate the policy setting with a small .Net application in VS2019. First I configured a connected service with ,,OData Connected Service'' extension in the project. That works fine until a try to load the policies for a specific report, but in the last step a recieve an error message: ,,A property with name 'Id' was found when reading a top-level resource set. No properties other than the resource set property with name 'value' are allowed.''

 

Here is my code:

using System;
using System.Linq;
using Model; // this is the namespace of the automatically generated OData client

namespace ODataTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var context = new Container(new Uri("https://my.company.com/Reports/api/v2.0"));

            context.Credentials = System.Net.CredentialCache.DefaultCredentials;

            PowerBIReport ci = context.PowerBIReports.Where(c => c.Path.Contains("SampleReport")).Single();
            context.LoadProperty(ci, "Policies"); // ERROR
        }
    }
}

the last line throws the error. I also tried the ,,expand'' method but it is not working with the report servers API. 

 

In my understanding the a LoadProperty command expects a json response like

{
    "values":[
    {
      "GroupUserName":"DOMAIN\User1","Roles":[
        {
          "Name":"Content Manager","Description":null
        }
      ]
    }, ....
    ]
}

however the a server send a response like this:

{
"@odata.context":"https://my.company.com/Reports/api/v2.0/$metadata#Collection(Model.ItemPolicy)",
    "Id":"00000000-0000-0000-0000-000000000000",
    "InheritParentPolicy":true,
    "Policies":[
    {
      "GroupUserName":"DOMAIN\User1","Roles":[
        {
          "Name":"Content Manager","Description":null
        }
      ]
    }, ....
    ]
}

 

Can You help to solve this issue? Thanks!

 

best,

Gallusz

 

p.s.: as a last resort I can do policy setting with pure put request, but I think the proper way is to use the OData client library with the connected service

1 REPLY 1
Icey
Community Support
Community Support

Hi @abaligetig ,

 

I don't know much about this. Just provide some troubleshooting directions:

 

1. Please break out and get the returned result of "context";

 

2.  Please check the report property used ("SampleReport") is the same as it shows in PBIRS and test with others.

 

3. Which .Net OData client are you using? Are there any updates and changes?

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.