dizzyzebra
dizzyzebra

Reputation: 23

Why does Graph API return a "not found" error when querying for user attributes?

I am relatively new to Microsoft Graph API. I am trying to extract a list of user profile information. When I run either of the following requests, I get a valid response:

Get displayname and birthday for single user:

GET https://graph.microsoft.com/v1.0/users/___userID___?$select=displayName,birthday

Get displayname for all users:

GET https://graph.microsoft.com/v1.0/users/?$select=displayName

However, when I try to run the following query, I receive an error:

Get displayname and birthday for all users:

GET https://graph.microsoft.com/v1.0/users/?$select=displayName,birthday

The error I receive is as follows:

{
    "error": {
        "code": "UnknownError",
        "message": "",
        "innerError": {
            "date": "2023-02-02T05:57:08",
            "request-id": "e8ae37af-3478-4446-a328-9d79f7aac0fc",
            "client-request-id": "a667c3f1-0183-3382-c601-2197456a758d"
        }
    }
}

This error seems to occur with only some attribute types, forexample hiredate and birthday. If I query for displayname and userprincipalname, I do get the same error.

I would appreciate any suggestions.

Upvotes: 1

Views: 1046

Answers (2)

dizzyzebra
dizzyzebra

Reputation: 23

For anyone reading this in the future, I was able to achieve my desired outcome using the following script.

Thanks to user2250152's answer, I realized I could not query for the necessary properties in bulk. So I used PowerShell to first pull a list of all users, and then loop through each of them to query the required properties.

# Report on User Profiles in SPO 

# Define attributes to query
$attributes = @("displayname","aboutMe","skills","interests","birthday","hireDate")

# Connect to Graph
Connect-MgGraph -Scopes "User.Read.All"
Select-MgProfile -Name beta

# Get list of active users
$users = Get-MgUser -All | Where-Object {($_.AccountEnabled -eq $true) -and ($_.OnPremisesSyncEnabled -eq $true) -and ($_.UserType -eq "Member")}

# Loop through all users and query for SPO profile attributes
$results = @()
foreach ($user in $users) {
    $query = Get-MgUser -UserID $user.Id -Select $attributes | Select-Object $attributes
    $results += $query   
    }

# Display Results
$results | Out-GridView

Upvotes: 1

user2250152
user2250152

Reputation: 20748

According to the documentation, properties aboutMe, birthday, hireDate, interests, mySite, pastProjects, preferredName, responsibilities, schools, skills, mailboxSettings cannot be returned within a user collection.

They are only supported when retrieving a single user.

Upvotes: 0

Related Questions