I'm trying to access Microsoft Planner data through Graphs API from SharePoint(Online) and getting success response message also.
But the problem is "DisplayName" field is null for all user sections in JSON data (such as createdBy, assignedBy,completedBy etc)
Example :
"assignments": {
"309249ab-fe3e-4ed7-8d64-3c6187527437": {
"#odata.type": "#microsoft.graph.plannerAssignment",
"assignedBy": {
"user": {
"displayName": null,
"id": "s33dfsdf-fe3e-4ed7-8d64-3c6187527437"
}
},
"createdBy": {
"user": {
"displayName": null,
"id": "fsdfsf-fe3e-4ed7-8d64-3c6187527437"
}
"completedBy": {
"user": {
"displayName": null,
"id": "fsdlhfdals-fe3e-4ed7-8d64-3c6187527437"
}
}
How to get the display names from Planner API?
Planner data does not include display names. Display names need to be obtained separately. Group membership information for the containing group (groups/<id>/members) will contain display name (and more) information for user ids returned in plan and task information, for all users who are still members of the group. The id of the group that contains the plan is specified by the owner field of the plan. Remaining users' information can be obtained by reading those users directly (users/<id>).
Related
So I've been trying to get email addresses of people that have access to certain files in a Sharepoint document library of a site through the use of the Microsoft Graph API. Below is an example of how my permission object looks like, which is retrieved from https://graph.microsoft.com/v1.0/sites/<site id>/drives/<drive id>/items/<item id>/permissions.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('...')/drives('...')/items('...')/permissions",
"value": [
{
"id": "...",
"roles": ["owner"],
"grantedTo": { "user": { "displayName": "testsite - Eigenaars" } },
"inheritedFrom": {}
},
{
"id": "...",
"roles": ["read"],
"grantedTo": { "user": {"displayName": "testsite - Bezoekers"} },
"inheritedFrom": {}
},
{
"id": "...",
"roles": ["write"],
"grantedTo": { "user": { "displayName": "testsite - Leden" } },
"inheritedFrom": {}
},
{
"id": "...",
"roles": [
"write"
],
"grantedToV2": {
"siteGroup": {
"displayName": "Developers",
"id": "120",
"loginName": "Developers"
}
},
"grantedTo": {
"user": {
"displayName": "Developers"
}
},
"inheritedFrom": {}
},
{
"id": "...",
"roles": ["owner"],
"grantedTo": {
"user": {
"email": "testsite#mysharepoint",
"id": "uuid",
"displayName": "testsite - Eigenaars"
}
},
"inheritedFrom": {}
}
]
}
I assume the testsite in the displayName property is a group name (probably the group that belongs to the site the file resides in), but I have seen cases where I can't find this group name in the groups retrieved from the /groups endpoint in the Graph API.
You can also see the group Developers, which I haven't managed to find in the full group list retrieved from /groups.
The documentation around this is quite vague and unclear to me. Somewhere I read that this lack of data could be due to authentication scopes, but I have "god mode" administrator rights in this Sharepoint environment, so that would seem strange to me.
My main goal is to be able to get all users that have access to a specific file.
Thanks in advance!
1. I assume the testsite in the displayName property is a group name, but I have seen cases where I can't find this group name in the groups retrieved from the /groups endpoint in the Graph API.
This is because as per Drive Item Permission >> Identity Set >> Identity resource type Quoting
The identity's display name. Note that this may not always be available or up to date. For example, if a user changes their display name, the API may show the new value in a future response, but the items associated with the user won't show up as having changed when using
This can explain why sometimes you don't see the group name in your groups.
I suggest you use the id.
2. My main goal is to be able to get all users that have access to a specific file.
Do you have any users that appear on the Has Access section of the drive item on sharepoint? For users you should be able to get permissions and use the ids to Get directoryObject using the id values from grantedToIdentitiesV2 or grantedToV2 which will return odate type.
GET https://graph.microsoft.com/v1.0/directoryObjects/{id}?$select=id
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects(id)/$entity",
"#odata.type": "#microsoft.graph.group or user or application",
"id": "id"
}
For groups, the users would be the members of the group.
I'm calling the List Assignments endpoint in Microsoft Graph. It returns an array of classes with one of the classes shown below.
How do I unpack the referenced entity microsoft.graph.educationAssignmentClassRecipient to get the recipient list?
{
"classId": "bef6024d-c51d-4c2d-9c4c-4e290581e7b4",
"displayName": "Teleschool Week 5 Formative Grade",
"closeDateTime": null,
"dueDateTime": "2020-04-28T03:59:59Z",
"assignDateTime": null,
"assignedDateTime": "2020-04-24T15:51:00.8911402Z",
"allowLateSubmissions": true,
"createdDateTime": "2020-04-24T15:50:39.9443371Z",
"lastModifiedDateTime": "2020-04-24T15:51:03.7407937Z",
"allowStudentsToAddResourcesToSubmission": true,
"status": "assigned",
"id": "66e4a8f8-42ee-49e0-9503-e24a49be6908",
"instructions": {
"content": "",
"contentType": "text"
},
"grading": {
"#odata.type": "#microsoft.graph.educationAssignmentPointsGradeType",
"maxPoints": 100
},
"assignTo": {
"#odata.type": "#microsoft.graph.educationAssignmentClassRecipient"
}
educationAssignmentClassRecipient {pasted from documentation}:
Used inside the assignment.assignTo property. When set to class recipient, every student in the class will receive a submission object when the assignment is published.
This resource is a subclass of educationAssignmentRecipient.
For an assignment that is handed out to the whole class, it'll contain the classRecipient data type.
For classRecipient, we do not include the full list of userIds. But you can query the ~/groups/{classId}/members API to get the member list OR to see exactly which user's were given out that assignment, you can query the ~/assignments/{id}/submissions list where each submission will contain the recipient/userId property.
For an assignment that was selectively handed out to a subset of students, it'll contains the #odata.type: IndividualRecipient and a recipient's array with the student's userIds.
We are getting the permissions of a driveItem using Microsoft Graph as documented here.
Each returned permission object usually contains a grantedTo field that has an IdentitySet as its value. But the issue with that is that each Identity is always a user:
"grantedTo": {
"user": {
"displayName": "data Owners",
"email": "data#example.onmicrosoft.com",
"id": "94c3e81b-f6fb-43c6-8df5-b98462ccf191"
}
}
"grantedTo": {
"user": {
"displayName": "Data Members"
}
}
This occurs even though those are Groups. So there's no way, using this data, to identify with certainty what is a Group and what is a User.
We want to avoid any additional request to do so as this can become quite inefficient.
Thus we are asking is there a way to identify if it is a group or user, without any additional API requests? For example some undocumented query parameters or relationships?
I'm afraid this isn't possible because the IdentitySet itself doesn't distinguish between Users and Groups:
{
"application": {"#odata.type": "microsoft.graph.identity"},
"device": {"#odata.type": "microsoft.graph.identity"},
"user": {"#odata.type": "microsoft.graph.identity"}
}
I'm sending a search request to the /me/drive/root/search endpoint. I'm specifying which fields to return using the $select query parameter as follows:
https://graph.microsoft.com/v1.0/me/drive/root/search(q='sdflkdshflkjhsdf')?$select=webUrl,name,lastModifiedDateTime,createdBy,lastModifiedBy,createdDateTime,folder,image,id
However the drive item objects returned are missing some of the fields I requested. For example here is the response to the above query:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
"#odata.nextLink": "https://graph.microsoft.com/v1.0/me/drive/root/search(q='sdflkdshflkjhsdf')?$select=webUrl%2cname%2clastModifiedDateTime%2ccreatedBy%2clastModifiedBy%2ccreatedDateTime%2cfolder%2cimage%2cid&$skiptoken=s!MTtlMDIzYmJlYi03NmUwLTRmMGUtYTljMy02MmE0MTNiM2RlZDE",
"value": [
{
"#odata.type": "#microsoft.graph.driveItem",
"createdDateTime": "2017-08-03T12:59:28Z",
"id": "01ZGVHW2FL7NNJJOD5AVGIMHTNV2BTATLB",
"lastModifiedDateTime": "2017-08-03T12:59:28Z",
"name": "sdflkdshflkjhsdf.pdf",
"webUrl": "https://[REDACTED].sharepoint.com/personal/oscar_[REDACTED]/Documents/sdflkdshflkjhsdf.pdf"
}
]
}
As you can see the createdBy and lastModifiedBy fields have not been returned. Are these fields not supported on this endpoint? The documentation says the endpoint returns full DriveItem objects which should include these fields.
I had same issue. In documentation is said, that
Drive Recent
Drive Item search that both should return the same object DriveItem.
When I tried to search
https://graph.microsoft.com/v1.0/me/drive/root/search(q='MY_RECENT_DOC.docx')?$top=1
gave me response without createdBy or lastModifiedBy.
But when i used 'recent API', the same object with the all information was presented.
https://graph.microsoft.com/v1.0/me/drive/recent?$top=1
Like #oscar-robinson said you can use id (what is always visible) and this id you can use to another search where all information will be presented.
https://graph.microsoft.com/v1.0/me/drive/items/{id}
In my application, the user signs in using their Office365 credentials and then
I want to import the data of the users (id, mail, displayName) in the same
organization into my database.
When another person from the same organization logs in into my app, that other
person should see the same list of users as the first one.
I tried several queries in the Graph Explorer, but none
of them has a response, which would allow to determine that two people belong
to the same organization.
"My profile" (/v1.0/me/) response contains a lot
of data, but no tenant ID (or something similar):
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"id": "16f5a7b6-5a15-4568-aa5a-31bb117e9967",
"businessPhones": [],
"displayName": "Anne Weiler",
"givenName": "Anne",
"jobTitle": "Manufacturing Lead",
"mail": "annew#CIE493742.onmicrosoft.com",
"mobilePhone": "+1 3528700812",
"officeLocation": null,
"preferredLanguage": "en-US",
"surname": "Weiler",
"userPrincipalName": "annew#CIE493742.onmicrosoft.com"
}
Same applies to the "all users in the organization" (/v1.0/users) response.
How can I extract the information from Microsoft Graph that would allow me to
detect that two different users work in the same organization?
You could use the id returned by the /organiozation endpoint:
https://graph.microsoft.com/v1.0/organization?$select=id,displayName
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#organization(id,displayName)",
"value": [
{
"id": "c07ab59f-ce09-49f8-b4c4-9c6dd4f0d8bb",
"displayName": "Microsoft API Sandbox"
}
]
}