How to filter group members in Microsoft graph API? - asp.net-web-api2

I was sure about after reading Microsoft document that I can filter the group members using OData Query Parameters because https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/group_list_members
Request GET URL - https://graph.microsoft.com/v1.0/groups/{groupId}/members?filter= startswith(givenname,'V')
In above URL groupId is used from https://graph.microsoft.com/v1.0/groups
but when I try to get the result using Graph Explorer (https://developer.microsoft.com/en-us/graph/graph-explorer) using my work account login, it's not working.
Also I have tried to use this in SDK (I have implemented graph API in my code using Microsoft graph API SDK) and still got same error.
And gives below error -
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "The specified filter to the reference property query is currently not supported.",
"innerError": {
"request-id": "96f3ffef-56f5-42e3-82f2-64813106b729",
"date": "2018-02-13T10:59:39"
}
}
}
Is this because "members" is not a resource type ? so it does not have properties and so we can not filter this result ?
If so then is there any other way we can get filtered group members ?
Also posted issue on Github - https://github.com/microsoftgraph/microsoft-graph-docs/issues/2239

Add ConsistencyLevel: eventual to Your request header (should work for v1.0 and beta as well)

Filtering of group members is now available as a beta API.
GET https://graph.microsoft.com/beta/groups/{id}/members?$count=true&$filter=startswith(displayName, 'a')

Here's how you would impelment it in code
//testing the filter query here
// Get groups user is a member of
// GET /me/memberOf
var myfilteredUserGroups = await _graphClient.Me.MemberOf
.Request(queryOptions)
.Header("ConsistencyLevel", "eventual")
.Filter("startswith(displayName, 'sa')")
.Select("displayName,groupTypes,id")
.Top(GraphConstants.PageSize)
.GetAsync();
// This method casts the returned DirectoryObjects
// as Group object, and filters out any non-Group objects
model.MyFilteredGroups = await GetAllPagesAsType<Group>(
_graphClient, myfilteredUserGroups);
return View(model);

Related

Microsoft Graph API odata $filter query does not appear to work

I am trying to filter a set of data returned by the MS Graph API's managedDevices endpoint using an odata filter.
Sending the request without a filter gets the expected result.
GET https://graph.microsoft.com/beta/deviceManagement/managedDevices
returns this response:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#deviceManagement/managedDevices",
"#odata.count": 5,
"value": [
{
"id": "kj23kj4-0d47-34f3-8ff0-6b5sdfsdf3332f",
"userId": "asdfasw-1b48-436d-aa42-3werwer2344",
"deviceName": "some_device_name_9/16/2020_6:31 PM"
...
When I send any of the following requests I get the exact same response with 5 results:
GET https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$filter=id eq 'kj23kj4-0d47-34f3-8ff0-6b5sdfsdf3332f'
GET https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$filter=id in ('lksjdf...','qwerqwer...')
GET https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$filter=ownerType ne 'personal'
I didn't see this listed on uservoice as an issue others are having specifically. They also apparently don't explicitly call out what odata query params are and aren't supported for specific endpoints. $select, for example, does work on this endpoint.
For this problem, I test it in my side also can't do the filter. And the odata url is correct, so I think the field id just not be designed to do filter.
If you want to do filter with id, you can use https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/{id} directly. It can get the result with specific "id", maybe it is why the field id not be designed to do filter.

How to filter items updated since a specific date in podio

I am trying to retrieve all items from my Podio app that were updated since a specific date.
I tried the https://api.podio.com/item/app/{id}/filter API filtering on the last_event_on attribute but the API returns "error_description": "Invalid value \"last_event_on\" (string): Invalid filtering key"
How can I achieve this ?
I could create a View with updated items since Yesterday and call the API /item/app/{app_id}/filter/{view_id}/ everyday but it does not seem robust. I would rather pass specificaly the date of my last call to the API.
Nicolas
Found the solution within the documentation.
The available filters are listed within the View doc and not the filter one : https://developers.podio.com/doc/filters
Filter using the last_edit_on key which differs from the last_event_onin the response.
{
"filters":{
"last_edit_on": {
"from": "2017-07-10 18:27:03"
}
}
}

How to get all Storage ID to Authorize with VM ID..?

I want to authorize a storage with VMs. For that I need to have all the VM ID's for a storage and those I get using the following call:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Network_Storage_Iscsi/9653497/getAllowableVirtualGuests?objectMask=mask[id,fullyQualifiedDomainName]
This gives me all the VM ID's corresponding to 9653497 (storage/order ID). However, I need to have all those storage ID's (like 9653497) which are not assigned to any of the VM's ID. I am using below call to get all storage ID:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Account/getNetworkStorage?objectMask=mask[id,username,nasType,storageType, billingItem[description,location[id,longName]]]&objectFilter={"networkStorage":{"nasType":{"operation":"ISCSI"},"billingItem":{"description":{"operation":"Endurance Storage"}}}}
the data that you are using for the filter probably are wrong, try to call the get object method GET /SoftLayer_Network_Storage/9653497/getObject?objectMask=mask[nasType,billingItem[description]] and see if the values of the request are the same as of your objectFilter
The filter in your request, gets Block Storage("nasType":{"operation":"ISCSI"}), maybe you need the File Storage. We can remove it to get more "Endurance" items (Block and File).
Please try the following removing some filters:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Account/getNetworkStorage?objectMask=mask[id,username,nasType,storageType, billingItem[description,location[id,longName]]]&objectFilter={ "networkStorage": { "billingItem": { "description": { "operation": "Endurance Storage" } } } }
Method: GET
if we don't want to get only Endurance, we can remove that filter too.
But when trying to add some properties using objectMasks to SoftLayer_Account::getNetworkStorage like allowableVirtualGuests, that property is not present in SoftLayer_Network_Storage.
For that reason the unique way to get “getAllowableVirtualGuests” is using SoftLayer_Network_Storage::getAllowableVirtualGuests

INVALID_ARGUMENT exception when requesting Google's knowledge graph API

I've read the documentation on Google's knowledge graph and from what I understand we can search for results both based on a query and based on IDs. For getting results by a query, no problem whatsoever, but when I try to retrieve them by IDs, it fails. Setting aside what query I used myself, this is the request URL I got from Google's API Explorer:
https://kgsearch.googleapis.com/v1/entities:search?ids=kg%3A%2Fm%2F01nrz4&key={YOUR_API_KEY}
and the result is:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
And I'm pretty sure that the problem is with the ids parameter. Am I missing something?
Thanks
OK, so here's the thing. Each found instance has an attribute like this: "#id": "kg:/m/0gkg6" . So in this instance the id is kg:/m/0gkg6, but when we want to run a query based on ID, we should omit the kg: part.

RavenDB Authorization Bundle proper user of SecureFor

I am attempting to use RavenDB's authorization bundle to limit the results of a query (on WorkItems) by the permissions that have been explicitly set on WorkItem documents.
For example:
I have a user bob#bob.com with a userId of /users/1 and a WorkItem that has the following permissions set in the Meta-Data:
"Raven-Document-Authorization": {
"Tags": [],
"Permissions": [
{
"Operation": "/Operations/WorkItem/Search",
"User": "users/1",
"Role": null,
"Allow": true,
"Priority": 1
}
]
}
I would then expect the following code to limit a query (from Bob's perspective) to this one WorkItem, because that is all he has permission to.
using (var session = documentStore.OpenSession())
{
session.SecureFor("raven/authorization/users/1", "/Operations/WorkItem/Search");
var workItemsQuery = from wi in session.Query<WorkItem>()
select wi;
var debts = workItemsQuery.ToList();
// do something with the work items
}
I based my code on the following example from RavenDB's documentation (Context & User section): http://ravendb.net/docs/2.5/server/extending/bundles/authorization-bundle-design
What I am getting instead is WorkItems that have no explicit permissions set. This is very puzzling to me because if I run the following code:
using (var session = mDocumentStore.OpenSession())
{
var answer = session.Advanced.IsOperationAllowedOnDocument(userId, operation, securableId);
var allowed = answer.IsAllowed;
}
allowed is true.
One additional item of note, I am attempting to ignore or simply not use the authorization bundle's concept of role and I wonder if this is having some unintended effect.
It is very possible that I am misunderstanding their example, could anyone shed any light on this subject for me? Thanks in advance.
Also, I wondered if the issue I am encountering was related to this StackOverflow question: RavenDB: Raven Query not returning correct count with document authorization, but their issue seems to be with the count and not necessarily the actual results.
Just to tiddy up this question, I will provide an answer to what was causing my problem. The issue was related to the use of "raven/authorization/users/1" syntax. When I changed the search command to simply use, "users/1" it worked correctly.