1+ import * as common from './common' ;
2+ import * as nodeApi from 'azure-devops-node-api' ;
3+
4+ import * as ProfileApi from 'azure-devops-node-api/ProfileApi' ;
5+ import * as ProfileInterfaces from 'azure-devops-node-api/interfaces/ProfileInterfaces' ;
6+
7+ export async function run ( projectId : string ) {
8+ const webApi : nodeApi . WebApi = await common . getWebApi ( ) ;
9+ const profileApiObject : ProfileApi . IProfileApi = await webApi . getProfileApi ( ) ;
10+ common . banner ( 'Profile Samples' ) ;
11+
12+ common . heading ( 'Create a profile' ) ;
13+ const createProfileContext : ProfileInterfaces . CreateProfileContext = { cIData : null ,
14+ contactWithOffers : false ,
15+ countryName : 'US' ,
16+ displayName : null ,
17+ emailAddress : 'sample@microsoft.com' ,
18+ hasAccount : false ,
19+ language : 'english' ,
20+ phoneNumber : '123456890' } ;
21+ let profile : ProfileInterfaces . Profile = await profileApiObject . createProfile ( createProfileContext , false ) ;
22+ console . log ( 'Profile created for' , profile . coreAttributes . DisplayName . value ) ;
23+
24+ common . heading ( 'Update the profile' ) ;
25+ const email = profile . coreAttributes . UnconfirmedEmailAddress . value ;
26+ profile . coreAttributes . UnconfirmedEmailAddress . value = 'Changed@microsoft.com' ;
27+ await profileApiObject . updateProfile ( profile , profile . id ) ;
28+ profile = await profileApiObject . getProfile ( profile . id , true , true ) ;
29+ console . log ( 'Profile now has email' , profile . coreAttributes . UnconfirmedEmailAddress . value ) ;
30+ console . log ( 'Reverting name' ) ;
31+ profile . coreAttributes . UnconfirmedEmailAddress . value = email ;
32+ await profileApiObject . updateProfile ( profile , profile . id ) ;
33+ console . log ( 'Profile email reverted to' , profile . coreAttributes . UnconfirmedEmailAddress . value ) ;
34+
35+ common . heading ( 'Get the avatar' ) ;
36+ const avatar : ProfileInterfaces . Avatar = await profileApiObject . getAvatar ( profile . id ) ;
37+ console . log ( "Avatar value:" , avatar . value ) ;
38+
39+ common . heading ( 'Get region information' ) ;
40+ const regions : ProfileInterfaces . ProfileRegions = await profileApiObject . getRegions ( ) ;
41+ console . log ( `There are ${ regions . regions . length } regions found including regions like ${ regions . regions [ 0 ] . name } ` ) ;
42+ }
0 commit comments