Jquery Cannot Use in Operator to Search for result in Received Upload:
In this article, I volition continue showing how to execute the calls to Microsoft Graph API using some optional OData query parameters.
The function-1 of this article serial can be establish hither. Let'due south at present see the remaining query parameters one by i.
$select
Explanation
When yous fire an API telephone call to MS Graph, it will render the JSON result with all the properties. Yous may not demand all the properties of a event set e'er. When you want MS Graph API to return only certain properties, then use $select parameter to specify which properties you desire in outcome fix.
Please note that the no. of records in the upshot volition not be affected with or without $select parameter, only what's returned for each record in result will change.
Example
Open up MS Graph Explorer hither and fire the following call to become a list of files from OneDrive:
- https://graph.microsoft.com/v1.0/me/bulldoze/root/children or click here, and then press "Run Query"
See the data returned in JSON response.
Post-obit is the upshot JSON snippet containing some of the values.
- {
- "createdBy" : {
- "user" : {
- "displayName" : "Megan Bowen"
- }
- },
- "createdDateTime" : "2017-07-31T18:56:29Z" ,
- "id" : "01BYE5RZ6QN3ZWBTUFOFD3GSPGOHDJD36K" ,
- "lastModifiedDateTime" : "2017-07-31T18:56:29Z" ,
- "proper noun" : "Attachments" ,
- "folder" : {
- "childCount" : 0
- },
- "size" : 0
- },
- {
- "createdBy" : {
- "user" : {
- "displayName" : "Megan Bowen"
- }
- },
- "createdDateTime" : "2017-08-07T16:18:24Z" ,
- "id" : "01BYE5RZ4CPC5XBOTZCFD2CT7SZFNICEYC" ,
- "lastModifiedDateTime" : "2017-08-07T16:eighteen:24Z" ,
- "name" : "Contoso Clothing" ,
- "binder" : {
- "childCount" : xiv
- },
- "size" : 5912877
- }
Out of all these properties, what may exist virtually important for you if you wanted to bear witness the user his/her files from OneDrive? Of grade, the proper name of the file/folder.
Fire following call in MS Graph Explorer to go but file proper noun in consequence.
- https://graph.microsoft.com/v1.0/me/drive/root/children?$select=proper noun or click here, and then printing "Run Query"
You lot will see the following upshot.
Following is the consequence JSON snippet containing some of the values.
- {
- "value" : [
- {
- "@odata.etag" : "\"{60F36ED0-85CE-4771-B349-E671C691EFCA},one\"" ,
- "proper name" : "Attachments"
- },
- {
- "@odata.etag" : "\"{A9D9C2AC-FF32-42EE-87C3-283CFCE061E1},1\"" ,
- "name" : "Business organisation Data"
- },
- {
- "@odata.etag" : "\"{73E9E609-FA05-42D8-82BD-1239D821CDD8},1\"" ,
- "name" : "Class Documents"
- }
- ]
- }
Now, MS Graph API returns but file/folder name, instead of all the details. (Of grade, "etag" is included but ignore it)
You tin can also employ more than ane property separated past comma, e.thou.
- https://graph.microsoft.com/v1.0/me/bulldoze/root/children?$select=name,size
And, you will get the following result.
Post-obit is the result JSON snippet containing some of the values.
- {
- "value" : [
- {
- "@odata.etag" : "\"{60F36ED0-85CE-4771-B349-E671C691EFCA},ane\"" ,
- "proper name" : "Attachments" ,
- "size" : 0
- },
- {
- "@odata.etag" : "\"{A9D9C2AC-FF32-42EE-87C3-283CFCE061E1},1\"" ,
- "name" : "Business organization Data" ,
- "size" : 39566226
- }
- ]
- }
If you blazon in the property that does not be in the consequence ready, and then information technology will be ignored.
due east.thou. - fire the following phone call and see what happens:
- https://graph.microsoft.com/v1.0/me?$select=salary
Usage
In your programming, you can use $select query parameter to,
- Get only specific property in result prepare (to make efficient use of bandwidth)
- Specify those properties not returned in default upshot set
$search
Caption
Using $search query parameter, you can specify costless text search criteria for items beingness returned in upshot set. Please note that this parameter is currently supported for simply "messages" and "person" entities. Microsoft Graph team volition cover more than entities after.
Some programmers are confused between $search and $filter parameters because both practise similar operations. I will explain the deviation briefly in the next section for the $filter.
When you specify $search parameter, it tells MS Graph API to include only those entities in the event which match the specified expression. Hither what to match is left for the implementer, OData specification does non mandate anything. Hence when you specify search criteria with $search query parameter, the result volition be dependent on what MS Graph API team has decided to implement. Mostly it works as complimentary text search.
Instance
Let'south say you desire to detect out emails which have "brainstorming" mentioned somewhere.
Open MS Graph Explorer here and burn down the following call.
- https://graph.microsoft.com/v1.0/me/letters?$search=brainstorming or click here, then press "Run Query"
See the data returned in JSON response.
Following is the result JSON snippet containing some of the values.
- {
- "value" : [
- {
- "createdDateTime" : "2017-09-08T05:57:44Z" ,
- "lastModifiedDateTime" : "2017-09-08T05:57:45Z" ,
- "hasAttachments" : false ,
- "subject" : "DG2000+ Brainstorming Session" ,
- "bodyPreview" : "Hello Production Launch Squad..." ,
- "importance" : "normal" ,
- "sender" : {
- "emailAddress" : {
- "proper noun" : "Miriam Graham" ,
- "address" : "MiriamG@M365x214355.onmicrosoft.com"
- }
- },
- "ccRecipients" : [],
- "bccRecipients" : [],
- "replyTo" : []
- }
- ]
- }
Graph API will match the word brainstorming in an email'due south from, discipline and trunk fields, and will testify the matching messages in the event.
Permit'south meet another example of using $search with "people" entity.
Open MS Graph Explorer here and fire following call:
- https://graph.microsoft.com/v1.0/me/people?$search=langer or click here, then printing "Run Query"
See the data returned in JSON response.
Post-obit is the effect JSON snippet containing some of the values.
- {
- "value" : [
- {
- "id" : "e3d0513b-449e-4198-ba6f-bd97ae7cae85" ,
- "displayName" : "Isaiah Langer" ,
- "givenName" : "Isaiah" ,
- "surname" : "Langer" ,
- "jobTitle" : "Web Marketing Manager" ,
- "section" : "Sales & Marketing" ,
- "phones" : [
- {
- "blazon" : "business organisation" ,
- "number" : "+1 918 555 0101"
- }
- ]
- }
- ]
- }
MS Graph API will search for the people related to the sample business relationship user, will search for "langer" in display proper name or email, and will return matching records in result.
At that place are many more than possible calls using the $search parameter, but I will restrict to these two calls simply for brevity. I encourage you to explore more by yourself.
Usage
In your programming, y'all can use $search parameter to:
- perform a free text search on letters or people related to user
- perform fuzzy searches on people
$filter
Explanation
With $filter parameter, you lot tin specify the filter criteria on a result set up using logical operators or cord functions. At that place are fixed logical and string operations which tin can be performed on a result set using $filter function.
The post-obit extract is taken from the OData specification website here
The $filter organization query selection allows clients to filter a collection of resources that are addressed by a request URL. The expression specified with $filter is evaluated for each resource in the collection, and merely items where the expression evaluates to truthful are included in the response.
Permit'south understand the difference between $search and $filter parameters,
- $search starts with an empty consequence fix and adds items to it based on criteria that match, while $filter takes full result fix, and removes items based on criteria that don't match.
- $search operates like a free text search, while $filter works on predefined logical and string functions.
Which logical and string functions are supported with $filter?
Every bit per current MS Graph API documentation, post-obit functions are supported, but the back up varies equally per which entity you lot are dealing with, so ever refer to latest documentation on Microsoft site:
- 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)
- non (not)
- startswith
- any
Instance
Let'south come across some examples of how you can employ $filter parameter.
Open MS Graph Explorer here and burn down the following call:
- https://graph.microsoft.com/v1.0/me/people?$filter=jobTitle eq zippo or click here, and so press "Run Query"
Run into the data returned in JSON response, it returns all "users" associated with the sample account whose chore title is not set,
Following is the result JSON snippet containing some of the values.
- {
- "value" : [
- {
- "displayName" : "Marketing" ,
- "jobTitle" : cipher
- },
- {
- "displayName" : "Product Launch Event" ,
- "jobTitle" : nil
- },
- {
- "displayName" : "Retail" ,
- "jobTitle" : null
- },
- {
- "displayName" : "Tailspin Toys" ,
- "jobTitle" : naught
- },
- {
- "displayName" : "Activewear" ,
- "jobTitle" : null
- }
- ]
- }
Similarly, if you want to see simply those records where job championship is set, then simply alter the operator "eq" (for equal to) to "ne" (for not equal to)
- https://graph.microsoft.com/v1.0/me/people?$filter=jobTitle ne null&$select=jobTitle,displayName or click here, then press "Run Query"
You lot volition see the following response which will listing all users who have chore title assigned,
Following is the result JSON snippet containing some of the values.
- {
- "value" : [
- {
- "id" : "e3d0513b-449e-4198-ba6f-bd97ae7cae85" ,
- "displayName" : "Isaiah Langer" ,
- "jobTitle" : "Web Marketing Director"
- },
- {
- "id" : "48d31887-5fad-4d73-a9f5-3c356e68a038" ,
- "displayName" : "Megan Bowen" ,
- "jobTitle" : "Accountant"
- },
- {
- "id" : "f5289423-7233-4d60-831a-fe107a8551cc" ,
- "displayName" : "Ben Walters" ,
- "jobTitle" : "VP Sales"
- }
- ]
- }
Delight annotation here that you come across only 2 properties in the response considering I also used the $select parameter in the API call. You can use "&" in an API phone call when you want to use more than than ane optional query parameter,
https://graph.microsoft.com/v1.0/me/people?$filter=jobTitle ne null&$select=jobTitle,displayName
In that location are much more uses of $filter parameter possible, but I will restrict to just two examples for brevity. I suggest you lot read more than on Microsoft Graph API documentation page here.
Usage
Use the $filter parameter in your programming to,
- brand API calls with logical operations for checking equality, greater than, less than, etc. operations
$skipToken
Caption
When a response from MS Graph API does non contain all the bachelor records (due to the user explicitly specifying to select merely some top records or due to server-side paging implemented in Graph API to limit response size), and so you will see the response contains a server generated value with the $skipToken parameter. This value is to be specified in the side by side phone call to MS Graph API and then that it volition render the next set up of records. The value of $skipToken is generated by the server, information technology can not be specified by you every bit a consumer.
Example
Burn down the following call to get merely peak ten files stored on user's OneDrive,
- https://graph.microsoft.com/v1.0/me/drive/root/children?$top=10 or click here, then press "Run Query"
Encounter the issue, annotation the value in @odata.nextLink property,
Following is the result JSON snippet containing some of the values,
- {
- "@odata.context" : "https://graph.microsoft.com/v1.0/$metadata#users('48d31887-5fad-4d73-a9f5-3c356e68a038')/drive/root/children" ,
- "@odata.nextLink" : "https:
- $skiptoken=Paged%3dTRUE%26p_SortBehavior%3d0%26p_FileLeafRef%3dAll%2520Japan%2520Revenues%2520By%2520City%252exlsx%26p_ID%3d33%26p_FileDirRef%3dpersonal%252fmeganb%255fm365x214355%255fonmicrosoft%255fcom%252fDocuments%26RootFolder%3d%252fpersonal%252fmeganb%255fm365x214355%255fonmicrosoft%255fcom%252fDocuments",
- "value" : [
- {
- }
- ]
- }
The @odata.nextLink property contains the call which should be fired to get the adjacent prepare of consequence. For identifying what should be returned, it has a skip token generated from server-side with some logic to skip those records in current response.
Simply fire the query mentioned in the @odata.nextLink holding, and you will get next ready of values.
Usage
- In your programming, you tin can use $skipToken to become paginated information (implement paging).
Limitations/Errors
Not all query parameters are supported for all entities. Always refer to latest Microsoft documentation for what's supported. I also suggest firing the call in MS Graph Explorer starting time and run across if you are getting the expected result or not, before starting whatever programming and later having any surprise.
If you include some query parameter for a non-supported entity, then MS Graph API will throw an appropriate error.
Allow's sympathise with an example.
Burn down the following telephone call in MS Graph Explorer:
- https://graph.microsoft.com/v1.0/users?$filter=123 or click here, so printing "Run Query"
Y'all will become error 400,
Post-obit is the result JSON snippet containing some of the values,
- {
- "error" : {
- "code" : "BadRequest" ,
- "message" : "Invalid filter clause" ,
- "innerError" : {
- "request-id" : "c19b6fbb-e3f4-4007-a012-eac483100272" ,
- "appointment" : "2017-xi-13T18:41:25"
- }
- }
- }
Using query parameter without '$' prefix in beta version of MS Graph API
With beta version of MS Graph API, using "$" prefix before a query parameter is optional.
Fire following phone call in MS Graph Explorer to get elevation 2 recently accessed files in result,
- https://graph.microsoft.com/beta/me/drive/recent?top=2 or click here, so press "Run Query"
Y'all will run into the following result,
Following is the result JSON snippet containing some of the values,
- {
- "value" : [
- {
- "@odata.blazon" : "#microsoft.graph.driveItem" ,
- "id" : "01BYE5RZ2KXWOTNNU3K5B3AZ4YMANXEMAE"
- },
- {
- "@odata.type" : "#microsoft.graph.driveItem" ,
- "id" : "01BYE5RZZ5OJSCSRM6BZDY7ZEFZ3NJ2QAY"
- }
- ]
- }
Note that the "peak" query parameter is used without any "$" prefix here and all the same you become only 2 records in effect.
This concludes my 2-part article serial on MS Graph API query parameters. I hope you enjoyed learning nearly how to use query parameters in the MS Graph API call.
I suggest yous keep reading more about MS Graph API until my next article (part-3).
Yous can read some of my articles on MS Graph API and Office 365 evolution hither.
Source: https://www.c-sharpcorner.com/article/using-optional-query-parameters-with-microsoft-graph-api-part-two/
0 Response to "Jquery Cannot Use in Operator to Search for result in Received Upload:"
Post a Comment