Skip to content

Commit 5ddd267

Browse files
committed
Add samples for the applications endpoint
1 parent 995b76d commit 5ddd267

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/applications_samples.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```py
2+
import asyncio
3+
4+
from azure.identity import EnvironmentCredential
5+
from kiota_abstractions.api_error import APIError
6+
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
7+
from msgraph import GraphRequestAdapter
8+
from msgraph import GraphServiceClient
9+
10+
# Set the event loop policy for Windows
11+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
12+
13+
# Create authentication provider object. Used to authenticate request
14+
credential=EnvironmentCredential()
15+
auth_provider = AzureIdentityAuthenticationProvider(credential)
16+
17+
# Initialize a request adapter. Handles the HTTP concerns.
18+
request_adapter = GraphRequestAdapter(auth_provider)
19+
20+
# Get a service client.
21+
client = GraphServiceClient(request_adapter)
22+
23+
# GET ALL APPLICATIONS IN THE TENANT
24+
# Request: GET /applications
25+
26+
async def get_applications():
27+
try:
28+
apps = await client.applications.get()
29+
if apps and apps.value:
30+
for app in apps.value:
31+
print(app.id)
32+
except APIError as e:
33+
print(e.error.message)
34+
asyncio.run(get_applications())
35+
```

0 commit comments

Comments
 (0)