使用VSTS API获取个人资料时个人账号遭遇ProfileNotFoundException求助
Hey there, let's break down why your personal account is hitting a ProfileNotFoundException while your school/enterprise account works fine with the API GET https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=1.0:
Key Context First
School/enterprise accounts are typically tied to Azure AD, which automatically provisions a user profile in the Visual Studio Services (VSS) ecosystem when you first access related services (like Azure DevOps). Personal Microsoft accounts (e.g., outlook.com, hotmail.com) don’t get this automatic provisioning—you need to trigger profile creation manually.
Step-by-Step Fixes to Try
Manually create your VSS profile with the personal account
Log into the Azure DevOps web portal using your personal account. Go through any initial setup prompts (like setting a display name or configuring your profile). This will create the necessary profile record in VSS, which the API needs to fetch data. After this, retry theprofiles/meAPI call.Update your API version
Theapi-version=1.0you’re using is quite outdated. Newer API versions have better support for personal accounts. Try switching to a recent stable version likeapi-version=7.1-preview.3or the latest stable release. Your updated request would look like:GET https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1-preview.3Verify your authentication token
Double-check the JWT token you’re using for the personal account:- Decode the token using an offline tool (to avoid external links)
- Ensure the
aud(audience) claim is set tohttps://app.vssps.visualstudio.com/ - Confirm the
scopesincludevso.profile_read—this permission is required to fetch profile data. If it’s missing, you’ll need to re-authenticate with the correct scope.
Try using your user ID instead of
/me
If/mestill fails after the above steps, first fetch your personal account’s user ID with this API call:GET https://app.vssps.visualstudio.com/_apis/connecteduser?api-version=7.1-preview.1Then replace
/mein your original request with the returned user ID, like:GET https://app.vssps.visualstudio.com/_apis/profile/profiles/{your-user-id}?api-version=7.1-preview.3
Why This Works for Enterprise/School Accounts
As mentioned earlier, enterprise/school accounts are integrated with Azure AD, which automatically creates a VSS profile when the account is added to the organization’s Azure AD tenant or when you first access VSS services. Personal accounts don’t have this automated setup, so the profile record doesn’t exist until you manually trigger it.
内容的提问来源于stack exchange,提问作者DevTard

