How to build a Ms graph api query filter on array object?

2.9k Views Asked by At

I am planning to leverage List Groups Ms graph API to list O365 groups in my organization and, later filter them for Yammer groups.

When I use this API in graph explorer it returns following response object.

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
  "@odata.nextLink": "https://graph.microsoft.com/v1.0/groups?,
  "value": [
    {
      "id": "",
      "description": "",
      "displayName": "",
      "groupTypes": [
        "Unified"
      ],
      "isAssignableToRole": null,
      "mail": "",
      "mailEnabled": true,
      "mailNickname": "",
      "onPremisesDomainName": null,
      "onPremisesLastSyncDateTime": null,
      "onPremisesNetBiosName": null,
      "onPremisesSamAccountName": null,
      "onPremisesSecurityIdentifier": null,
      "onPremisesSyncEnabled": null,
      "preferredDataLocation": null,
      "proxyAddresses": [
        "",
        "SMTP:",
        "smtp:"
      ],
      "renewedDateTime": "2018-09-07T16:23:37Z",
      "onPremisesProvisioningErrors": []
    },
    {
      "id": "",
      "deletedDateTime": null,
      "classification": null,
      "createdDateTime": "2019-01-11T17:34:30Z",
      "**creationOptions**": [
        "Team",
        "ExchangeProvisioningFlags"
      ],
      "description": "Discuss",
      "displayName": "I&O",
      "groupTypes": [
        "Unified"
      ],
      "isAssignableToRole": null,
      "mail": "",
      "preferredDataLocation": null,
      "proxyAddresses": [
        "SPO",
        "SMTP:",
        "smtp:"
      ],
      "renewedDateTime": "2019-01-11T17:34:30Z",
      "resourceBehaviorOptions": [],
      "resourceProvisioningOptions": [
        "Team"
      ],
      "onPremisesProvisioningErrors": []
    },
    {
      "id": "",
      "deletedDateTime": null,
      "classification": null,
      "createdDateTime": "2018-12-10T21:14:47Z",
      "**creationOptions**": [
        "YammerProvisioning"
      ],
      "description": "",
      "displayName": "",
      "groupTypes": [
        "Unified"
      ],
      "isAssignableToRole": null,
      "mailEnabled": true,
      "onPremisesDomainName": null,
      "onPremisesLastSyncDateTime": null,
      "onPremisesNetBiosName": null,
      "onPremisesSamAccountName": null,
      "onPremisesSecurityIdentifier": null,
      "onPremisesSyncEnabled": null,
      "preferredDataLocation": null,
      "proxyAddresses": [],
      "renewedDateTime": "2018-12-10T21:14:47Z",
      "resourceBehaviorOptions": [
        "CalendarMemberReadOnly"
      ],
      "resourceProvisioningOptions": [],
      "onPremisesProvisioningErrors": []
    }
  ]
}

As you can see each object in json has 'creationOptions', that means a group might have this field populated with some value. I am interested to return only those groups where creationOptions = YammerProvisioning.

But $filter could only applied on string and not on array so I am not sure how would right that query. I tried following but, its Invalid filter clause.

https://graph.microsoft.com/v1.0/groups?$filter=equals(creationOptions,'YammerProvisioning')

Another approach I tried is as follows, it gave same array.

https://graph.microsoft.com/v1.0/groups?$filter=startswith(creationOptions,['YammerProvisioning'])

My goal is to simple fetch all the groups having creationOptions as 'YammerProvisioning'

An help or examples are appreciated :) Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

This syntax should work, but it may be unsupported in v1.0. ?$filter=creationOptions/any(r:r+eq+'YammerProvisioning')

Beta endpoint doesn't seem to have creationOptions, but you could try going against resourceBehaviorOptions.

https://www.techmikael.com/2017/11/how-to-list-all-office-365-groups-which.html?m=1

Although it's not reliable in all tenants ("However, not all Yammer-enabled groups are reported by looking at the ResourceBehaviorOptions. It seems like Yammer communities that already used Office 365 Groups before the migration had the property configured while communities converted to Office 365 Groups during the migration did not. Perhaps some background process will update the property for the other groups over time.") https://office365itpros.com/2020/04/13/moving-yammer-networks-native-mode-microsoft-365/