Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions samples/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as common from './common';
import * as nodeApi from 'azure-devops-node-api';

import * as ProfileApi from 'azure-devops-node-api/ProfileApi';
import * as ProfileInterfaces from 'azure-devops-node-api/interfaces/ProfileInterfaces';

export async function run(projectId: string) {
const webApi: nodeApi.WebApi = await common.getWebApi();
const profileApiObject: ProfileApi.IProfileApi = await webApi.getProfileApi();
common.banner('Profile Samples');

common.heading('Create a profile');
const createProfileContext: ProfileInterfaces.CreateProfileContext = {cIData: null,
contactWithOffers: false,
countryName: 'US',
displayName: null,
emailAddress: 'sample@microsoft.com',
hasAccount: false,
language: 'english',
phoneNumber: '123456890'};
let profile: ProfileInterfaces.Profile = await profileApiObject.createProfile(createProfileContext, false);
console.log('Profile created for', profile.coreAttributes.DisplayName.value);

common.heading('Update the profile');
const email = profile.coreAttributes.UnconfirmedEmailAddress.value;
profile.coreAttributes.UnconfirmedEmailAddress.value = 'Changed@microsoft.com';
await profileApiObject.updateProfile(profile, profile.id);
profile = await profileApiObject.getProfile(profile.id, true, true);
console.log('Profile now has email', profile.coreAttributes.UnconfirmedEmailAddress.value);
console.log('Reverting name');
profile.coreAttributes.UnconfirmedEmailAddress.value = email;
await profileApiObject.updateProfile(profile, profile.id);
console.log('Profile email reverted to', profile.coreAttributes.UnconfirmedEmailAddress.value);

common.heading('Get the avatar');
const avatar: ProfileInterfaces.Avatar = await profileApiObject.getAvatar(profile.id);
console.log("Avatar value:", avatar.value);

common.heading('Get region information');
const regions: ProfileInterfaces.ProfileRegions = await profileApiObject.getRegions();
console.log(`There are ${regions.regions.length} regions found including regions like ${regions.regions[0].name}`);
}
1 change: 1 addition & 0 deletions samples/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"buildArtifact",
"creation",
"policy",
"profile",
"task",
"filecontainer",
"git",
Expand Down
1 change: 1 addition & 0 deletions samples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"buildArtifact.ts",
"creation.ts",
"policy.ts",
"profile.ts",
"task.ts",
"filecontainer.ts",
"git.ts",
Expand Down