Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating permissions report on Devops

Status
Not open for further replies.

5H4F33

Technical User
Jul 24, 2003
6
MU
Hello everybody,

I'm trying to create a permission report on devops using rest api. I'm following the below doc:
report/create?view=azure-devops-rest-6.0

Below is the code I currently have:

Code:
# Create needed variables
$OrganizationName = "myorg"
$AdminUser = "myemail@domain.com"
$Token = "pattoken"

# The Header is created with the given information.
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $AdminUser, $Token)))
$Header = @{
    Authorization = ("Basic {0}" -f $base64AuthInfo)
}

# Splat the parameters in a hashtable for readability
$Uri    = "[URL unfurl="true"]https://dev.azure.com/$OrganizationName/_apis/permissionsreport?api-version=6.0-preview.1"[/URL]

$Body = @{
    descriptors =   ""
    reportName  =   "testreport"
    resources   =   "collection"
}
# Store response
$Reports = (Invoke-RestMethod -Uri $Uri -Headers $Header -Method POST -Body $Body)
$Reports

Im getting below error:

Code:
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"The request indicated a Content-Type of \"application/x-[URL unfurl="true"]www-form-urlencoded\"[/URL] for method      
type \"POST\" which is not supported. Valid content types for this method are: application/json,
application/json-patch+json.","typeName":"Microsoft.VisualStudio.Services.WebApi.VssRequestContentTypeNotSupportedException,
Microsoft.VisualStudio.Services.WebApi","typeKey":"VssRequestContentTypeNotSupportedException","errorCode":0,"eventId":3000}
At C:\Data\az_permissions.ps1:21 char:13
+ $Reports = (Invoke-RestMethod -Uri $Uri -Headers $Header -Method POST ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Im not sure how to move forward. I'd appreciate any help.

Thanks & regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top