Skip to content

Commit 108f06a

Browse files
author
damccorm
authored
Added Profile Sample (#236)
* Added profile sample * Cleaning up
1 parent 5b83ac2 commit 108f06a

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

samples/profile.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

samples/samples.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"buildArtifact",
44
"creation",
55
"policy",
6+
"profile",
67
"task",
78
"filecontainer",
89
"git",

samples/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"buildArtifact.ts",
1111
"creation.ts",
1212
"policy.ts",
13+
"profile.ts",
1314
"task.ts",
1415
"filecontainer.ts",
1516
"git.ts",

0 commit comments

Comments
 (0)