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.

Office Development

Post-obit is the upshot JSON snippet containing some of the values.

  1. {
  2. "createdBy" : {
  3. "user" : {
  4. "displayName" : "Megan Bowen"
  5.     }
  6.   },
  7. "createdDateTime" : "2017-07-31T18:56:29Z" ,
  8. "id" : "01BYE5RZ6QN3ZWBTUFOFD3GSPGOHDJD36K" ,
  9. "lastModifiedDateTime" : "2017-07-31T18:56:29Z" ,
  10. "proper noun" : "Attachments" ,
  11. "folder" : {
  12. "childCount" : 0
  13.     },
  14. "size" : 0
  15. },
  16. {
  17. "createdBy" : {
  18. "user" : {
  19. "displayName" : "Megan Bowen"
  20.     }
  21.   },
  22. "createdDateTime" : "2017-08-07T16:18:24Z" ,
  23. "id" : "01BYE5RZ4CPC5XBOTZCFD2CT7SZFNICEYC" ,
  24. "lastModifiedDateTime" : "2017-08-07T16:eighteen:24Z" ,
  25. "name" : "Contoso Clothing" ,
  26. "binder" : {
  27. "childCount" : xiv
  28.   },
  29. "size" : 5912877
  30. }

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.

Office Development

Following is the consequence JSON snippet containing some of the values.

  1. {
  2. "value" : [
  3.     {
  4. "@odata.etag" : "\"{60F36ED0-85CE-4771-B349-E671C691EFCA},one\"" ,
  5. "proper name" : "Attachments"
  6.     },
  7.     {
  8. "@odata.etag" : "\"{A9D9C2AC-FF32-42EE-87C3-283CFCE061E1},1\"" ,
  9. "name" : "Business organisation Data"
  10.     },
  11.     {
  12. "@odata.etag" : "\"{73E9E609-FA05-42D8-82BD-1239D821CDD8},1\"" ,
  13. "name" : "Class Documents"
  14.     }
  15.   ]
  16. }

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.

Office Development

Post-obit is the result JSON snippet containing some of the values.

  1. {
  2. "value" : [
  3.     {
  4. "@odata.etag" : "\"{60F36ED0-85CE-4771-B349-E671C691EFCA},ane\"" ,
  5. "proper name" : "Attachments" ,
  6. "size" : 0
  7.     },
  8.     {
  9. "@odata.etag" : "\"{A9D9C2AC-FF32-42EE-87C3-283CFCE061E1},1\"" ,
  10. "name" : "Business organization Data" ,
  11. "size" : 39566226
  12.     }
  13.   ]
  14. }

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.

Office Development

Following is the result JSON snippet containing some of the values.

  1. {
  2. "value" : [
  3.       {
  4. "createdDateTime" : "2017-09-08T05:57:44Z" ,
  5. "lastModifiedDateTime" : "2017-09-08T05:57:45Z" ,
  6. "hasAttachments" : false ,
  7. "subject" : "DG2000+ Brainstorming Session" ,
  8. "bodyPreview" : "Hello Production Launch Squad..." ,
  9. "importance" : "normal" ,
  10. "sender" : {
  11. "emailAddress" : {
  12. "proper noun" : "Miriam Graham" ,
  13. "address" : "MiriamG@M365x214355.onmicrosoft.com"
  14.           }
  15.         },
  16. "ccRecipients" : [],
  17. "bccRecipients" : [],
  18. "replyTo" : []
  19.       }
  20.     ]
  21. }

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.

Office Development

Post-obit is the effect JSON snippet containing some of the values.

  1. {
  2. "value" : [
  3.       {
  4. "id" : "e3d0513b-449e-4198-ba6f-bd97ae7cae85" ,
  5. "displayName" : "Isaiah Langer" ,
  6. "givenName" : "Isaiah" ,
  7. "surname" : "Langer" ,
  8. "jobTitle" : "Web Marketing Manager" ,
  9. "section" : "Sales & Marketing" ,
  10. "phones" : [
  11.           {
  12. "blazon" : "business organisation" ,
  13. "number" : "+1 918 555 0101"
  14.           }
  15.         ]
  16.       }
  17.     ]
  18. }

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,

Office Development

Following is the result JSON snippet containing some of the values.

  1. {
  2. "value" : [
  3.       {
  4. "displayName" : "Marketing" ,
  5. "jobTitle" : cipher
  6.       },
  7.       {
  8. "displayName" : "Product Launch Event" ,
  9. "jobTitle" : nil
  10.       },
  11.       {
  12. "displayName" : "Retail" ,
  13. "jobTitle" : null
  14.       },
  15.       {
  16. "displayName" : "Tailspin Toys" ,
  17. "jobTitle" : naught
  18.       },
  19.       {
  20. "displayName" : "Activewear" ,
  21. "jobTitle" : null
  22.       }
  23.     ]
  24. }

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,

Office Development

Following is the result JSON snippet containing some of the values.

  1. {
  2. "value" : [
  3.       {
  4. "id" : "e3d0513b-449e-4198-ba6f-bd97ae7cae85" ,
  5. "displayName" : "Isaiah Langer" ,
  6. "jobTitle" : "Web Marketing Director"
  7.       },
  8.       {
  9. "id" : "48d31887-5fad-4d73-a9f5-3c356e68a038" ,
  10. "displayName" : "Megan Bowen" ,
  11. "jobTitle" : "Accountant"
  12.       },
  13.       {
  14. "id" : "f5289423-7233-4d60-831a-fe107a8551cc" ,
  15. "displayName" : "Ben Walters" ,
  16. "jobTitle" : "VP Sales"
  17.       }
  18.     ]
  19. }

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,

Office Development

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,

Office Development

Following is the result JSON snippet containing some of the values,

  1. {
  2. "@odata.context" : "https://graph.microsoft.com/v1.0/$metadata#users('48d31887-5fad-4d73-a9f5-3c356e68a038')/drive/root/children" ,
  3. "@odata.nextLink" : "https:
  4.   $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",
  5. "value" : [
  6.     {
  7.     }
  8.   ]
  9. }

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,

Office Development

Post-obit is the result JSON snippet containing some of the values,

  1. {
  2. "error" : {
  3. "code" : "BadRequest" ,
  4. "message" : "Invalid filter clause" ,
  5. "innerError" : {
  6. "request-id" : "c19b6fbb-e3f4-4007-a012-eac483100272" ,
  7. "appointment" : "2017-xi-13T18:41:25"
  8.     }
  9.   }
  10. }

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,

Office Development

Following is the result JSON snippet containing some of the values,

  1. {
  2. "value" : [
  3.     {
  4. "@odata.blazon" : "#microsoft.graph.driveItem" ,
  5. "id" : "01BYE5RZ2KXWOTNNU3K5B3AZ4YMANXEMAE"
  6.     },
  7.     {
  8. "@odata.type" : "#microsoft.graph.driveItem" ,
  9. "id" : "01BYE5RZZ5OJSCSRM6BZDY7ZEFZ3NJ2QAY"
  10.     }
  11.   ]
  12. }

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.

baumanhansorneve.blogspot.com

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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel