Write high quality code with the Microsoft Graph PHP SDK v2
In July 2022, we announced the public preview of the first Kiota generated SDK for PHP. Today, we are pleased to make this SDK generally available. The Microsoft Graph PHP SDK 2.0.0 offers best in class features to improve developer efficiency and code quality. By solving cross-cutting concerns like authentication, retry and batching, the SDK gives you time back to focus on the design and value of your application. Let’s explore some of its most important features.
The authentication provider wraps around PHP League’s OAuth 2.0 client, hence, its name – `GraphPhpLeagueAuthenticationProvider`.
The authentication provider supports the following flows:
- OAuth 2.0 auth code grant for delegated permissions.
- OAuth 2.0 client credentials grant for application permissions.
It also supports OAuth 2.0 on-behalf-of flow to request tokens on behalf of third-party applications.
The auth provider guarantees the token is always valid by tracking the expiration and automatically refreshing it in the background before it expires.
Fluent experience to build requests
Aided by the IDE’s autocomplete, the SDK helps you find the right command in each line of code, improving discoverability and reducing the time spent reading documentation. The SDK suggests only commands that work with the last typed instruction, reducing errors in your code.
Built-in retry handler
The SDK offers a configurable built-in Retry-Handler that understands 429 (Too Many Requests), 503 (Service Unavailable) and 504 (Gateway Timeout) response status codes, that usually require the application to retry the request after some time. The handler reads the recommendation in the `Retry-After` header and retries after the recommended time automatically. You can also customize the handler and specify a custom value for the `RetriesTimeLimit` greater than 0, to introduce time-based evaluated request retries with the default count-based request retry.
For performance reasons, collections of entities are often split into pages and each page is returned with a URL to the next page. The PageIterator class simplifies consuming of paged collections. PageIterator handles enumerating the current page and requesting subsequent pages automatically.
Combine multiple requests in a single call with ease. Up to 20 individual requests can be batched together to reduce network latency of making each request separately. The BatchRequestBuilder allows you to make requests to the /$batch endpoint of the Microsoft Graph API.
Uploading large files
To upload files larger than 3MB, Microsoft Graph API supports uploads using resumable upload sessions where several bytes are uploaded at a time. The SDK provides a LargeFileUpload task that slices your file into bytes and progressively uploads them until completion.
Try out the new version today!
Get started now with the Upgrade guide, the README and code samples. We have written a detailed description of the breaking changes introduced by this new version. You can also find the packages for the beta endpoint here.
Learn more about Microsoft Graph SDKs
The SDK includes a set of tools, libraries, and documentation that make it easy to get started building applications that take advantage of the rich data and insights available through Microsoft Graph API.
Start saving time and removing complexity in your code today. Sign up for the Microsoft 365 Developer Program to get a free Microsoft 365 developer. We also recommend that you join our Microsoft 365 Platform community calls and events and get involved with other developers who use Microsoft Graph and build solutions for Microsoft 365.
Here are some additional resources we have pulled together to help you get started.
- Explore our public documentation, where you can find how to install the SDK, authenticate, customize your client and more.
- Use the Microsoft Graph Explorer, a tool that lets you make requests and see responses against the Microsoft Graph, and which displays corresponding snippets to requests you make.
- Visit the Microsoft Graph Dev Center.
- Follow us on X (Twitter) / @Microsoft365Dev for the latest news and announcements.