Skip to content

Commit b200d79

Browse files
author
Danny McCormick
authored
Get profile samples working (#307)
1 parent 6f647c7 commit b200d79

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

samples/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ function getEnv(name: string): string {
1010
return val;
1111
}
1212

13-
export async function getWebApi(): Promise<vm.WebApi> {
14-
let serverUrl = getEnv("API_URL");
13+
export async function getWebApi(serverUrl?: string): Promise<vm.WebApi> {
14+
serverUrl = serverUrl || getEnv("API_URL");
1515
return await this.getApi(serverUrl);
1616
}
1717

samples/profile.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@ import * as ProfileApi from "azure-devops-node-api/ProfileApi";
55
import * as ProfileInterfaces from "azure-devops-node-api/interfaces/ProfileInterfaces";
66

77
export async function run(projectId: string) {
8-
const webApi: nodeApi.WebApi = await common.getWebApi();
8+
let serverUrl = process.env["API_URL"];
9+
// Profile api can't be hit at the org level, has to be hit at the deployment level, so url should be structured like set API_URL=https://vssps.dev.azure.com/{orgName}
10+
serverUrl = serverUrl.replace('://dev.azure.com', '://vssps.dev.azure.com');
11+
console.log('serverUrl', serverUrl);
12+
const webApi: nodeApi.WebApi = await common.getWebApi(serverUrl);
913
const profileApiObject: ProfileApi.IProfileApi = await webApi.getProfileApi();
1014
common.banner("Profile Samples");
1115

1216
common.heading("Create a profile");
1317
const createProfileContext: ProfileInterfaces.CreateProfileContext = {cIData: null,
1418
contactWithOffers: false,
1519
countryName: "US",
16-
displayName: null,
20+
displayName: "displayedName",
1721
emailAddress: "sample@microsoft.com",
1822
hasAccount: false,
1923
language: "english",
2024
phoneNumber: "123456890"};
2125
let profile: ProfileInterfaces.Profile = await profileApiObject.createProfile(createProfileContext, false);
2226
console.log("Profile created for", profile.coreAttributes.DisplayName.value);
23-
24-
common.heading("Get the avatar");
25-
const avatar: ProfileInterfaces.Avatar = await profileApiObject.getAvatar(profile.id);
26-
console.log("Avatar value:", avatar.value);
27-
28-
common.heading("Get region information");
29-
const regions: ProfileInterfaces.ProfileRegions = await profileApiObject.getRegions();
30-
console.log(`There are ${regions.regions.length} regions found including regions like ${regions.regions[0].name}`);
3127
}

0 commit comments

Comments
 (0)