microsoft / azure-devops-extension-api

REST client libraries and contracts for Azure DevOps web extension developers.
MIT License
99 stars 47 forks source link

ReleaseRestClient not work : error 401 but BuildRestClient is ok #2

Closed auriou closed 5 years ago

auriou commented 5 years ago

Hello, when i use the api release, i get a 401 error, while i am administrator on my project and my site azureDevOps

Thx for your help.

import * as SDK from "azure-devops-extension-sdk";
import { CommonServiceIds, IProjectPageService, getClient } from "azure-devops-extension-api";
import * as vsrelease from "azure-devops-extension-api/Release";
import * as vsbuild from "azure-devops-extension-api/Build";

await SDK.ready();
// get current project name
const projectService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
const project = await projectService.getProject();
let projectName = '';
if(project !== undefined) projectName = project.name;
console.log(projectName);

// get buildDefinitions = ok 
const buildDefinitions = await getClient(vsbuild.BuildRestClient).getDefinitions(
    projectName, undefined, undefined, undefined, 
    undefined, undefined, undefined, undefined, undefined, 
    undefined, undefined, undefined, true, true );
console.log(buildDefinitions);

// get releaseDefinitions   ==  error  401 ??
// {"$id":"1","innerException":null,"message":"TF400813: The user 'my admin guid' is not authorized to access this resource.","typeName":"Microsoft.TeamFoundation.Framework.Server.InvalidIdentityException, Microsoft.TeamFoundation.Framework.Server","typeKey":"InvalidIdentityException","errorCode":0,"eventId":3000}
const releaseDefinitions = await getClient(vsrelease.ReleaseRestClient).getReleaseDefinitions(projectName);
console.log(releaseDefinitions);
auriou commented 5 years ago

You must add rights to the manifest file of the extension

 "scopes": [
    "vso.release",
    "vso.build"
  ],

And you will have to authorize the new rights on AzureDevOps in the general extension section