cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
dmitry_onyschen Frequent Visitor
Frequent Visitor

ERROR 0 when trying update policies using API

I receive error {"error": {"code": "0","message": ""}}

when trying to update policies for PowerBIReports or Folders using API (PUT-request)

I am trying to use:

* python requests module

* python urllib.request

* PowerShell

* Postman

but the result is the same. In this tyme GET and POST requests working correctly in all cases

 

Please help me solve this problem!

 

For example here is my PowerShell script:

 

$username = "bi\Dmitry.on"
$password = "######"
$userpass  = $username + ":" + $password
$bytes= [System.Text.Encoding]::UTF8.GetBytes($userpass)
$encodedlogin=[Convert]::ToBase64String($bytes)
$authheader = "Basic " + $encodedlogin
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization",$authheader)
$headers.Add("Accept","application/json")
$headers.Add("Content-Type","application/json")
$uri = "http://#######/Reports/api/v2.0/Folders(3c07816e-83a1-4145-904a-b0fd5e92511f)/Policies"

$data_json = '[{"InheritParentPolicy": false,
"Policies": [  {"GroupUserName": "bi\\Dmitry.on","Roles": [  {"Name": "Content Manager", "Description": "May manage content in the Report Server. This includes folders, reports and resources."
  }] }]}]'

$data_converted = ConvertFrom-Json –InputObject $data_json
$response = Invoke-RestMethod -Uri $uri -Headers $headers -Method PUT -Body $data_converted
Write-Host $response

Here is part of my python script:

 

 

headers = {'Content-Type': 'multipart/form-data', 'accept': 'application/json'}
data = [
  {"InheritParentPolicy": False,
    "Policies": [
      {"GroupUserName": "bi\\dmitry.on",
        "Roles": [
          {"Name": "Content Manager",
            "Description": "May manage content in the Report Server. This includes folders, reports and resources."
          }]}]}]

v_result = s.put(url, headers=headers, data=data)

 

 

Here are errors in RSPortal log:

2019-08-14 08:26:22.9937|INFO|18|Received request PUT /api/v2.0/Folders%283c07816e-83a1-4145-904a-b0fd5e92511f%29/Policies| RequestID = s_224a6a4f-8d65-433f-9ffe-0e9fa0feac78 
2019-08-14 08:26:23.2124|ERROR|18|OData exception occurred: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.ReportingServices.Portal.Repositories.CatalogItemRepository.SetItemPolicy(IPrincipal userPrincipal, String itemPath, ItemPolicy itemPolicy)
   at Microsoft.ReportingServices.Portal.ODataWebApi.V2.Controllers.CatalogItemController`1.PutPolicies(String key, ItemPolicy policies)
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext().| RequestID = s_224a6a4f-8d65-433f-9ffe-0e9fa0feac78 
2019-08-14 08:26:23.2124|INFO|34|Sending response. Response code bi\dmitry.on 500, Elapsed time 0:00:00,2127784| RequestID = s_224a6a4f-8d65-433f-9ffe-0e9fa0feac78 
2019-08-14 08:47:49.9665|INFO|22|Received request PUT /api/v2.0/Folders%283c07816e-83a1-4145-904a-b0fd5e92511f%29/Policies| RequestID = s_de6ece1b-e316-4f59-a2c9-60cec432f884 
2019-08-14 08:47:50.0446|ERROR|22|OData exception occurred: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.ReportingServices.Portal.Repositories.CatalogItemRepository.SetItemPolicy(IPrincipal userPrincipal, String itemPath, ItemPolicy itemPolicy)
   at Microsoft.ReportingServices.Portal.ODataWebApi.V2.Controllers.CatalogItemController`1.PutPolicies(String key, ItemPolicy policies)
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext().| RequestID = s_de6ece1b-e316-4f59-a2c9-60cec432f884 
2019-08-14 08:47:50.0446|INFO|22|Sending response. Response code bi\Dmitry.on 500, Elapsed time 0:00:00.0770578| RequestID = s_de6ece1b-e316-4f59-a2c9-60cec432f884 
2019-08-14 08:52:28.9726|INFO|60|Received request GET /api/v2.0/Folders| RequestID = s_15d2dbfe-0ea1-4285-928a-cddfd19e8aad 
2019-08-14 08:52:29.0833|INFO|58|Sending response. Response code bi\dmitry.on 200, Elapsed time 0:00:00.1049904| RequestID = s_15d2dbfe-0ea1-4285-928a-cddfd19e8aad 
2019-08-14 08:52:29.3646|INFO|60|Received request PUT /api/v2.0/Folders%283c07816e-83a1-4145-904a-b0fd5e92511f%29/Policies| RequestID = s_c4811470-9c60-4b34-b7a5-7a35e50da757 
2019-08-14 08:52:29.3958|ERROR|60|OData exception occurred: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.ReportingServices.Portal.Repositories.CatalogItemRepository.SetItemPolicy(IPrincipal userPrincipal, String itemPath, ItemPolicy itemPolicy)
   at Microsoft.ReportingServices.Portal.ODataWebApi.V2.Controllers.CatalogItemController`1.PutPolicies(String key, ItemPolicy policies)
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext().| RequestID = s_c4811470-9c60-4b34-b7a5-7a35e50da757 
2019-08-14 08:52:29.3958|INFO|62|Sending response. Response code bi\dmitry.on 500, Elapsed time 0:00:00.0270003| RequestID = s_c4811470-9c60-4b34-b7a5-7a35e50da757 
1 ACCEPTED SOLUTION

Accepted Solutions
dmitry_onyschen Frequent Visitor
Frequent Visitor

Re: ERROR 0 when trying update policies using API

solved!

The body must be a string ))

View solution in original post

1 REPLY 1
dmitry_onyschen Frequent Visitor
Frequent Visitor

Re: ERROR 0 when trying update policies using API

solved!

The body must be a string ))

View solution in original post

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors