Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dmitry_onyschen
Regular 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
dmitry_onyschen
Regular Visitor

solved!

The body must be a string ))

View solution in original post

2 REPLIES 2
dmitry_onyschen
Regular Visitor

solved!

The body must be a string ))

Sorry but I'm getting the exact same error and still couldn't solve it. I'm doing the PUT request this way:

object[] oArr = new object[] {
    new {
        InheritParentPolicy = inheritParentPolicy
    }
};
RestRequest request = new RestRequest(string.Format("/Folders({0})/Policies", itemId), Method.PUT);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(oArr);
IRestResponse response = _client.Execute(request);

It's not an Authentication issue or something related as I'm already doing other GET, POST and PUT requests and all is working fin.

Any ideas? Thanks a lot!! 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors