I try to make a call from a powershell script to the analytics API from my private agent, and I get the following error response:
[error]Invoke-RestMethod : {"error":{"code":"0","message":"Using this service requires \"View Analytics\" permission on
I checked my security settings for "View analytics" and it says 'Allow'.
The PAT I've set my private agent up with has all scopes enabled.
I can access this API through Postman using another PAT with authorization Basic.
Also, if I change my header in my powershell script from:
$header = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
to:
$header = @{Authorization = "Basic <hard coded base64 encoded string used in the header for my Postman queries>"}
it works.
Question: What's going on?
The
System_Accesstoken
is the token that generated dynamically during the build/release, it isn’t the token that you used to configure the agent.The token that you used to configure agent is used only for the initial configuration of the agent.
To grant the permission to the service account for build/release:
project collection build service
in filter users and groups search box and selectProject Collection build Service (xxx)
user (not group)View analytics
to allow.