Advanced usage of Microsoft Graph

Implement Azure Security for Developers

Anushika Agarwal

Cloud Data Engineer

Analogy: grocery trips

  • Carry groceries in smaller trips

  • Lighter, faster, and safer

Grocery trips

Implement Azure Security for Developers

Pagination

  • Splits large results into smaller pages
  • Faster responses and fewer timeouts
  • How next pages are fetched?

Pagination

Implement Azure Security for Developers

Example: PeopleSphere using Pagination

  • Thousands of employee records retrieved in manageable pages

Example - PeopleSphere Pagination

Implement Azure Security for Developers

Server-side pagination

  • Service picks a default page size
  • Client does not specify the size
  • Example
    • GET /v1.0/users : (default) It returns 100 items per page

Server-Side Pagination

Implement Azure Security for Developers

Client-side pagination

  • Client specifies the items to return per page

Client-Side Pagination

Implement Azure Security for Developers

Query parameters for pagination

  • Query Parameters

    • $top: number of items per page.

    Query Parameters - Top

  • $skip: offset; start after the first N items

    Query Parameters - Skip

Implement Azure Security for Developers

Client-side pagination example

  • Example:
    • https://graph.microsoft.com/v1.0/groups?$top=2

Client-Side Pagination

Implement Azure Security for Developers

Batching Analogy: online shopping cart

  • Multiple items in one cart
  • One checkout, one receipt

Analogy - Online shopping cart

Implement Azure Security for Developers

Batching

  • Combine multiple Graph requests in one HTTP call
  • One payload -> one response with all results

  • Benefits

    • Fewer trips, lower latency
    • Ideal for dashboards.
  • Limit

    • Up to 20 requests per batch

Batching

Implement Azure Security for Developers

Batch request endpoint

  • Endpoint

    • Method: POST
    • Endpoint:https://graph.microsoft.com/v1.0/$batch
  • $batch instead of specific resource like users

Batch request endpoint

Implement Azure Security for Developers

Batch request body

  • Body is JSON object
  • Contains one property: requests
  • requests is an array (up to 20 items)
{ "requests": 
   [ {
      "id": "1",
      "method": "GET",
      "url": "/me/memberOf"
    },
    {
      "id": "2",
      "method": "GET",
      "url": "/me/planner/tasks"
    } ]
}
Implement Azure Security for Developers

Request items and headers

  • Each request item needs

    • id: unique label to match response
    • method: (GET/POST/PATCH/DELETE)
    • url: relative path
  • Headers: Content-Type: application/json

{ "requests": 
   [ {
      "id": "1",
      "method": "GET",
      "url": "/me/memberOf"
    },
    {
      "id": "2",
      "method": "GET",
      "url": "/me/planner/tasks"
    } ]
}
Implement Azure Security for Developers

Batch response

  • Each entry represents one request
{
  "responses": [
    {  "id": "1", 
        "status": 200, 
        "body": { "value": [/* ... */]}},
    { 
        "id": "2", 
        "status": 403, 
        "body": { "error": [/* ... */]}}
  ]
}

Implement Azure Security for Developers

What each response includes

  • Each response item includes

    • id: matches the original request

    • status: HTTP status for that item

      • 200: OK
      • 403: Forbidden
    • headers: (e.g., Content-Type)

    • body: data or error object

{
  "responses": [
    {  "id": "1", 
        "status": 200, 
        "body": { "value": [/* ... */]}},
    { 
        "id": "2", 
        "status": 403, 
        "body": { "error": [/* ... */]}}
  ]
}

Implement Azure Security for Developers

Let's practice!

Implement Azure Security for Developers

Preparing Video For Download...