Ability to filter users with onPremisesSamAccountName with Microsoft Graph API - azure-active-directory

I would like to filter Users from Microsoft Graph API based on onPremisesSamAccountName, which is currently not available with Graph API.
We have the internal employee id to be stored with onPremisesSamAccountName variable which is present in users API of Microsoft Graph. We are trying to filter with onPremisesSamAccountName property to filter based on the internal employee id. Currently, we are not able to do that with Graph API but we really need this to be working or would be happy if we get to know any possible workarounds.
https://graph.microsoft.com/v1.0/users?$filter=onPremisesSamAccountName eq '[some-id]'&$select= userPrincipalName,displayName,department,jobTitle,companyName,onPremisesSamAccountName,....[more list of fields for select]
The expected outcome is to show the required result but the response what we got is as follows:
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'onPremisesSamAccountName' of resource 'User'.",
"innerError": {
"request-id": "[request-id from request]",
"date": "[date on which request is made]"
}
}
}

As you can see, the filter is not supported for property 'onPremisesSamAccountName'.
If you do have this requirement, you can post your idea at Microsoft Graph UserVoice.

I was able to do a filter using onPremisesUserPrincipalName - you could check what is returned using this property and see if you can make it work

Related

Error using '/directoryObjects/validateProperties' API: Invalid entity type provided

When using the directoryObjects/validateProperties API for creating/validating AD Group properties, a 400 error is returned indicating 'Invalid entity provided. Supported entities include: Group'. I have confirmed that the only entityType I am providing in the request is 'Group' or 'group'.
{ code: 'Request_BadRequest',
message:
'Invalid entity type provided. Supported entities include: Group.',
innerError:
{ 'request-id': '4949163f-43c4-42e8-b016-436af61e4eb5',
date: '2020-06-11T10:29:08' } } }
The error occurs in both /v1.0 and /beta versions of the MS Azure AD API, with the body/payload stringified or not.
Not exactly sure what is expected. Can someone please provide assistance on this? Thanks.
I have validated the properties by using the same JSON Data from the document in the Graph explorer and it worked for me.
This is the below data which I have given
{
"entityType": "Group",
"displayName": "Myprefix_test_mysuffix",
"mailNickname": "Myprefix_test_mysuffix",
"onBehalfOfUserId": "1ab4e79f-5f52-44b8-8c72-7d03c05e6ff4"
}
And I am hitting the V1.0 endpoint
https://graph.microsoft.com/v1.0/directoryObjects/validateProperties
Try with my sample copying it change the onBehalfOfUserID to your userID and hit the same Http call in Graph Explorer.

query data in a airtable database using url

I want to implement URL for search specific data in my base using filterByFormula
below are my link and I got an error and how to resolve that
my url:
api.airtable.com/v0/APPID/Stories?filterByFormula=(FIND(“Car (in robot form) will offer a hug when I am stressed out”,{User want}) &api_key=MYKEY
Error :
{
"error": {
"type": "INVALID_FILTER_BY_FORMULA",
"message": "The formula for filtering records is invalid: Invalid formula. Please check your formula text."
}
}
I tried using postman, please help me.
While querying filtered data from Airtable via API, you don't have to use FIND keyword. You can filter data with simple Airtable formula like structure. For example,
{Email} = 'johnwick#neverdie.com'
Above filter retrieve all the records from the table whose Email is simply johnwick#neverdie.com
To limit number of records retrieve by API maxRecord parameter is available for that. For more info about various parameters please refer my answer here AirTable API Find record by email or official Airtable API Documentation
In your case
API url would be structured like,
api.airtable.com/v0/APPID/Stories?filterByFormula=Car+(in+robot+form)+will+offer+a+hug+when+I+am+stressed+out%3D%22User+want%22&api_key=MYKEY
For more info about Airtable API encoding, check this https://codepen.io/airtable/full/rLKkYB?baseId=app1C5TVoophmmr8M&tableId=tblvILr4aSAYI98oa
Hope this helps!

How to update the users birthday

I want to update the birthday of a user using the patch request.
Updating other properties works as expected but the moment the birthday property is included, the following error returned:
The request is currently not supported on the targeted entity set
I already tried to update the user to be sure the permissions are fine.
Application permissions are used.
This PATCH request to /V1.0/users/{id} works:
{
"givenName": "Fridas"
}
Passing this request body however:
{
"givenName":"Fridas",
"birthday" : "2014-01-01T00:00:00Z
}
throws an error
{
"error":
{
"code":"BadRequest",
"message":"The request is currently not supported on the targeted entity set",
"innerError":
{
"request-id":"5f0d36d1-0bff-437b-9dc8-5579a7ec6e72",
"date":"2019-08-13T15:27:40"
}
}
}
When I update the birthday separately, I get a 500 error. Print screens below. Updating the user id works fine, birthday does not.
Same user id is used in the request.
I'm not sure why this happens, but a workaround, albeit an annoying one, is to update birthday separately from other attributes.
E.g.
PATCH https://graph.microsoft.com/v1.0/users/userid
{
"birthday" : "2014-01-01T00:00:00Z"
}
Here is a screenshot from MS Graph Explorer:
In fact, this is a limitation in the current system.
User is a composite type. Under the covers some properties in user are mastered by different services, and we currently don't support updates across multiple services.
"birthday" is not mastered by Azure AD. So we can't update it with other properties mastered by Azure AD in the same call.
It is strongly recommended that you update this property separately. I can update it from my side. So you need a backend engineer to track this request for you.
This seems to affect more than Birthday.
Skills[] and Responsibilities[] are also returning 500 Internal Server Error when using PATCH request via REST API with:
{"skills": ["TESTING", "ANOTHER SKILL"]}
Same happens via the GraphServiceClient - except the result is:
Failed to call the Web Api: InternalServerError
Content: {
"error": {"code": "-1, Microsoft.Office.Server.Directory.DirectoryObjectUnauthorizedAccessException",
"message": "Attempted to perform an unauthorized operation.",
"innerError": {
"request-id": "1c2ccc54-0a0c-468f-a18c-6bdfbad4077d",
"date": "2019-08-28T13:23:55"
}}}
These requests work on the Graph Explorer page, but not via calls to the API.

Microsoft Graph API - Get directory objects from a list of ids - Bad request

I need to get a list of groups that the user is a member of using Microsoft Graph API.
For this, I am using the endpoint POST /users/<userId>/getMemberGroups (doc). This works fine but the problem is that the response is only a list of group object ids. I need to get group properties too. I could just loop through the list and query API for GET /groups/<groupId> but this takes too long when the user has multiple groups.
Then I found POST /directoryObjects/getById (doc) which turns that list into what I need. I have followed the doc page exactly but I am getting the following error:
Request_BadRequest - Specified HTTP method is not allowed for the request target. (HTTP status 405)
What am I doing wrong? Is the method getById bugged? If it is, is there any alternative way to turn a list of group object ids into groups or to get full list of user groups?
The API Get directory objects from a list of ids you mentioned should work, I test it in the MS Graph Explorer, it works fine.
Make sure you use POST method, I can reproduce your issue with another method.
You could refer to the informations below and try again.
Request URL:
POST https://graph.microsoft.com/beta/directoryObjects/getByIds
Request Body:
{
"ids": [
"xxxxxxxx-9f1b-4f28-a408-xxxxxxxxxxxx",
"xxxxxxxx-a614-4335-81eb-xxxxxxxxxxxx",
"xxxxxxxx-e500-49d6-a705-xxxxxxxxxxxx",
"xxxxxxxx-5be3-41eb-864d-xxxxxxxxxxxx",
"xxxxxxxx-961d-4db9-87cf-xxxxxxxxxxxx",
"xxxxxxxx-93bf-4950-8d96-xxxxxxxxxxxx"
],
"types": [
"group"
]
}
Result:

Filter groupType works on groups but not on memberOf

I can get all unified groups from azure active directory quite easily, especially cause it is explicitly mentioned within the documentation:
GET https://graph.microsoft.com/v1.0/groups?filter=groupTypes/any(c:c+eq+'Unified')
And you can get all groups a user belongs to with this query:
GET https://graph.microsoft.com/v1.0/users/{user-id}/memberOf
Now lets combine those two queries to get all unified groups a user belongs to:
GET https://graph.microsoft.com/v1.0/users/{user-id}/memberOf?filter=groupTypes/any(c:c+eq+'Unified')
and you'll get back:
HTTP Status Code 400
{
"error": {
"code": "BadRequest",
"message": "Filter not supported.",
"innerError": {
"request-id": "{request-id}",
"date": "2018-07-06T07:29:52"
}
}
}
Okay, so groups supports lambda query, so let's expand on that and enhance the filter to also filter on members:
GET https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified') and members/any(u:u/id+eq+'{user-id}')
But this returns
HTTP Status Code 400
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported Query.",
"innerError": {
"request-id": "{request-id}",
"date": "2018-07-06T07:41:47"
}
}
}
So, why isn't any of this supported (also not in beta)?
Please try using the below query to get all unified groups a user belongs to -
GET https://graph.microsoft.com/v1.0/Users/{user-id}/memberOf/$/microsoft.graph.group?$filter=groupTypes/any(c:c+eq+'Unified')
So, why isn't any of this supported (also not in beta)?
$filter is not supported by List memberOf Rest API. We could get that information from List memberOf Rest API document.
This method supports the OData Query Parameters to help customize the response. $filter is not supported.
From List Group Rest API, we could know that there no any properties related to user.
So you try to filter on members is not supported.
As SaurabhSharma-MSFT mentioned that you could use following way to do that.
GET https://graph.microsoft.com/v1.0/Users/{user-id}/memberOf/$/microsoft.graph.group?$filter=groupTypes/any(c:c+eq+'Unified')

Resources