Microsoft Graph API using filter on get sharepoint lists - microsoft-graph-api

I'm trying to filter on the sharepoint lists, but the semantics seems to be different to the default semantics.
What I already tried was (with $ and without; single quotes and no quotes):
https://graph.microsoft.com/v1.0/sites/root/lists?filter=name eq 'Something'
https://graph.microsoft.com/v1.0/sites/root/lists?$filter=name eq 'Something'
https://graph.microsoft.com/v1.0/sites/root/lists?filter=id eq 'CFFF1460-B4D7-419C-A921-61B5279BBDDC'
https://graph.microsoft.com/v1.0/sites/root/lists?$filter=id eq 'CFFF1460-B4D7-419C-A921-61B5279BBDDC'
https://graph.microsoft.com/v1.0/sites/root/lists?filter=id eq CFFF1460-B4D7-419C-A921-61B5279BBDDC
https://graph.microsoft.com/v1.0/sites/root/lists?$filter=id eq CFFF1460-B4D7-419C-A921-61B5279BBDDC
But everything returns an array containing all lists and not only the subset matching the desired criteria.
So how can I filter on sharepoint lists?

If you know the id of the list you want to filter and get a response for.
YOu can run a graph API query like this.
https://graph.microsoft.com/v1.0/sites/root/lists/{list-id}
This will give you data about that list.
Let me know if you need further details on this.

Unfortunately (like Marc already mentioned in the comments) it is not possible to filter on SharePoint lists. If you need to, you have to do it on the client side, by reading the list without any filter and make a LINQ statement (or something similar) on the received collection. Be aware that (like all collections in Graph) you don't get always all elements at once. Potentially you have to call the next link request from the last response and wade through more requests and elements till you find what you need.
So when you found what you need, it is a good idea to store the list id within a memory cache or Redis cache for faster lookups the next time, you need this information.

Related

Using endsWith filter together with expanding user's memberOf doesn't work

I want to fetch all users together with their group names from MS Graph API.
It works as long as I don't want to do some advanced filtering (endsWith()).
Here's the select query I'm running:
https://graph.microsoft.com/v1.0/users?$select=displayName,userPrincipalName,mail,id,givenName,surname,memberOf&$expand=memberOf($select=displayName)
It produces a nice set of users together with the display name's of groups they are in.
I wanted to restrict the result to a specific mail domain (i have added ConsistencyLevel: eventual), however I am unable to do it unless I remove the memberOf expand. This works:
https://graph.microsoft.com/v1.0/users?$select=displayName,userPrincipalName,mail,id,givenName,surname,memberOf&$count=true&$filter=endsWith(mail,'#somedomain.com')
But as expected, there are no groups. In fact, there are no groups at all despite selecting memberOf! I thought I'll just fetch groups first and then pair them in my code, but to get them I must expand, and with expand the filter doesn't work!
This produces an Request_UnsupportedQuery error:
https://graph.microsoft.com/v1.0/users?$select=displayName,userPrincipalName,mail,id,givenName,surname,memberOf&$expand=memberOf($select=displayName)&$count=true&$filter=endsWith(mail,'#somedomain.com')
Is there any way to achieve what I want without filtering manually or issuing multiple requests and mapping stuff on my own? We're talking about directories containing tens of thousands of users.. Graph seemed to be nice at the beginning but as I wanted to do anything more complex it turns out to be a limited POS where one query totally excludes another. I was also unable to filter by the expanded memberOf in any way
Based on Microsoft Docs
$expand is not currently supported with advanced queries.

What is the difference between the filter and search query parameters in Microsoft Graph Mail API?

While I was looking at the documentation for query parameters here, I noticed that there were two query parameters that seemingly did the exact same thing: filter and search.
I'm just wondering what the difference is between them and when is one used over the other.
While they're similar, they operate a little differently.
$search uses Keyword Query Language (KQL) and is only supported by message and person collections (i.e. you can't use $search on most endpoints). By default, it searches multiple properties. Most importantly, $search is a "contains" search, meaning it will look for your search word/phrase anywhere within a string.
For example, /messages?$search="bacon" will search for the word "bacon" anywhere in the from, subject, or body properties.
Unlike $search, the $filter parameter only searches the specified property and does not support "contains" search. It also works with just about every endpoint. In most places, it supports the following operators: equals (eq), not equals (ne), greater than (gt), greater than or equals (ge), less than (lt), less than or equals (le), and (and), or (or), not (not), and (on some endpoints) starts with (startsWith).
For example, /messages?$filter=subject eq 'bacon' will return only messages where the subject is "bacon".
Both search and filter reduce the result set that you ultimately receive, however they operate in different ways.
Search operates on the query against the entire graph and reduces the amount of information a search query returns. This is often optimized for queries that search is good at, e.g. performing searches for items that can be indexed.
Filter operates on the much smaller result set returned by the search to provide more fine grain filtering. Separating this out allows filtering to perform tasks that would not be performant against the full collection.
This is indicated in Microsoft's documentation:
Search: Returns results based on search criteria.
Filter: Filters results (rows). (results that could be returned by search)
For performance purposes, it's good to use both if you can, search to narrow the results (e.g. using search indexes) and then do fine grain filtering on the returned results.

Visual studio online query items without tags

When are working with various Work Item types (user stories,Tasks, etc) we assign tags to reference the area of work. This makes it easy to filter the Backlogs items view to find any related stories.
I would like to build a query to identify Work Items where the tags have not yet been assigned.
I know this can be achieved using excel and filtering, however I specifically would like to do this using the queries. Is this possible??
Thanks in advance for any assistance.
Firstly, I have to say that it is not possible to create work item query to show work items which don't contain tags. As you see that the Operator for Tags is Contains or Does Not Contain, it is not possible to use these two operators to filter out these non-tagged work items.
Secondly, as you have more than 100 tags, it is not an effective way to use "Does Not Contain" operator to exclude all tagged work items.
So,
How about you adding a 'Null' tag to all non-tagged work items to specify that these work items don't have any tags? With this approach, you can create a work item query with Tags Contains Null to list these non-tagged work items.
If you don't want to take this approach, you need to work with excel just as you mentioned above, or take Dave's advice to work with API.

Parsing Wikipedia countries, regions, cities

Is it possible to get a list of all Wikipedia countries, regions and cities with relations between them? I couldn't find any API appropriate for this task.
What is be the easiest way to parse all the information I need?
PS: I know, that there are another datasources I can get this information from. But I am interested in Wikipedia...
[2020 update] this is now best done using the Wikidata Query Service, you can run super specific queries with a bit of SPARQL, example: Find all countries and their label. See Wikidata Query Help
It might be a bit tedious to get the whole graph but you can get most of the data from the experimental/non-official Wikidata Query API.
I suggest the following workflow:
Go to an instance of the kind of entities you want to work with, say Estonia (Q191) and look for its instance of (P31) properties, you will find: country, sovereign state, member of the UN, member of the EU, etc.
Use the Wikidata Query API claim command to output every entity
that as the chosen P31 property. Lets try with country (Q6256):
http://wdq.wmflabs.org/api?q=claim[31:6256]
It outputs an array of numeric ids: that's your countries! (notice that the result is still incomplete as there are only 141 items found: either countries are missing from Wikidata, or, as suggested by Nemo in comments, some countries are to be found in country (Q6256) subclasses(P279))
You may want more than ids though, so you can ask Wikidata Official API for entities data:
https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q16&format=json&props=labels|claims&languages=en|fr
(here Canada(Q16) data, in json, with only claims and labels data, in English and French. Look at the documentation to adapt parameters to your needs)
You can query multiple entities at a time, with a limit of 50, as follow:
https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q16|Q17|Q20|Q27|Q28|Q29|Q30|Q31|Q32|Q33|Q34|Q35|Q36|Q37|Q38|Q39|Q40|Q41|Q43|Q45|Q77|Q79|Q96|Q114&format=json&props=labels|claims&languages=en|fr
From every countries data, you could look for entities registered as administrative subdivisions (P150) and repeat on those new entities.
Aternatively, you can get all the tree of administrative subdivisions with the tree command. For instance, for France(Q142) that would be http://wdq.wmflabs.org/api?q=tree[142][150] Tadaaa, 36994 items! But that's way harder to refine given the different kinds of subdivision you can encounter from a country to another. And avoid doing this kind of query from a browser, it might crash.
You now just have to find cities by countries by refining this last query with the claim command, and the appropriate sub-class(P279) of municipality(Q15284) entity (all available here): for France, that's commune (Q484170), so your request looks like
http://wdq.wmflabs.org/api?q=tree[142][150] AND claim[31:484170]
then repeat for all the countries: have fun!
You should go with Wikidata and/or dbpedia.
Personally I'd start with Wikidata as it's directly using MediaWiki, with the same API so you can use similar code. I would use pywikibot to get started. Like that you can still request pages from Wikipedia where that makes sense (e.g. list pages or categories).
Here's a nice overview of ways to access Wikidata

fogbugz: Is there a way to view the history of a case using the api

I want to get all the history of a case. Is this possible through the api?
Execute the search command, supplying the bug ID as the query (q parameter) and asking for the events column in the results (with the cols parameter). The URL for this will look like:
http://server/api.asp?cmd=search&q=1000&cols=events&token=xxx
In the returned XML, the <case> element (there will be just one if the bug ID is valid) will have an <events> child element with <event> children containing the history; the XML format is documented in the API documentation. If you just wanted to dump the comments on a case, for example, you could enumerate the results of the XPath query /response/cases/case/events/event/s.
The folks at Fog Creek Software have started a fantastic "StackExchange" using, essentially, the same software as Stack Overflow. You might want to check it out.
Fogbugz Knowledge Exchange

Resources