Advanced usage of Microsoft Graph
1. Advanced usage of Microsoft Graph
Building on our Graph overview, this video introduces pagination and batching. These are the concepts that make Microsoft Graph calls faster, lighter, and more efficient.2. Analogy: grocery trips
Think of moving groceries from your car, you take several trips instead of carrying everything at once. Pagination in Graph works the same way.3. Pagination
Pagination splits large results into smaller pages, making responses faster and preventing timeouts. In Microsoft Graph, when more results remain, a continuation link called @odata.nextLink points to the next batch until the final page is reached.4. Example: PeopleSphere using Pagination
For example, PeopleSphere may fetch thousands of employee records. With pagination, data arrives in smaller pages, making it easier for the HR app to process.5. Server-side pagination
Pagination requests can be handled in two ways, based on who chooses the page size. First is server-side pagination. Graph returns its default number of items per page. For this the client doesn't need to specify a size. For example, `GET /users` returns 100 results per page by default. If more exist, the response includes a continuation link to the next page.6. Client-side pagination
The second type is client-side pagination. Here, the client specifies how many items to return per page.7. Query parameters for pagination
This is set through query parameters. First, `$top` it specifies the number of items per page. $skip sets an offset so results start after the first N items. Not all endpoints support it. It helps jump to a page, but token-based pagination with nextLink is usually more efficient for moving between pages.8. Client-side pagination example
For example, this endpoint asks for groups with up to two items per page.9. Batching Analogy: online shopping cart
Now think of online shopping instead of placing five separate orders, you add all five items to one cart and check out once. You make one payment and receive one confirmation that lists everything. That’s batching.10. Batching
In Graph, batching combines multiple API requests into a single HTTP call using the $batch endpoint. You send one payload and get one combined response. This means fewer trips and lower latency, which is ideal for dashboards. A single batch can include up to 20 requests.11. Batch request endpoint
To make a batch request, you set the method to POST and call the $batch endpoint. Notice this uses $batch instead of resource paths like /users.12. Batch request body
Next comes the body. It is a JSON object with one top-level property: "requests". This is an array which can take up to 20 items.13. Request items and headers
Each request item has three fields. First is id which is a unique label to match the response. Second is method and Finally, url is a relative path like /users. If a request has a body, include headers and set Content-Type: `application/json` so Graph can read it.14. Batch response
Now that we know how requests are sent, let’s look at the response. At the top level you’ll see "responses" this is an array where each entry represents one request.15. What each response includes
Each entry includes four parts. First, id which is a string that matches back to the original request. Second, is status which is the HTTP status for that request. Next, the headers that carry extra metadata. Finally, body that is either the data or an error object.16. Let's practice!
Now that you know the basics, let’s jump into practice!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.