Skip to content

Commit 51d1976

Browse files
committed
Update samples to reflect breaking changes
1 parent 284e03d commit 51d1976

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ request_adapter = GraphRequestAdapter(auth_provider)
101101
client = GraphServiceClient(request_adapter)
102102

103103
async def get_user():
104-
user = await client.users_by_id('userPrincipalName').get()
104+
user = await client.users.by_user_id('userPrincipalName').get()
105105
print(user.display_name)
106106

107107
asyncio.run(get_user())
@@ -133,11 +133,12 @@ asyncio.run(me())
133133

134134
Failed requests raise `APIError` exceptions. You can handle these exceptions using `try` `catch` statements.
135135
```py
136+
from kiota_abstractions.api_error import APIError
136137
async def get_user():
137138
try:
138-
user = await client.users_by_id('userID').get()
139+
user = await client.users.by_user_id('userID').get()
139140
print(user.user_principal_name, user.display_name, user.id)
140-
except Exception as e:
141+
except APIError as e:
141142
print(f'Error: {e.error.message}')
142143

143144
asyncio.run(get_user())

UPGRADING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This package (`msgraph-sdk`) will only contain models that match the [Microsoft
3434
resp =client.get('/users/userId/messages')
3535

3636
# msgraph-sdk
37-
req = client.users_by_id('userId').messages().get()
37+
req = client.users.by_user_id('userId').messages.get()
3838
resp = asyncio.run(req)
3939
```
4040

@@ -120,7 +120,7 @@ request_config = MessagesRequestBuilder.MessagesRequestBuilderGetRequestConfigur
120120
query_parameters=query_params,
121121
)
122122

123-
messages = asyncio.run(client.users_by_id('userId').messages().get(request_configuration=request_config))
123+
messages = asyncio.run(client.users.by_user_id('userId').messages.get(request_configuration=request_config))
124124
for msg in messages.value:
125125
print(msg.subject)
126126
```
@@ -129,15 +129,15 @@ See [the examples](docs/Examples.md) on how to pass headers in your requests.
129129

130130
## Exception handling
131131

132-
Any `4xx` or `5xx` responses from the Graph API will result in an `ApiException` being thrown.
132+
Any `4xx` or `5xx` responses from the Graph API will result in an `APIError` being thrown.
133133

134134
```py
135-
135+
from kiota_abstractions.api_error import APIError
136136
try:
137137
users = asyncio.run(client.users().get())
138138

139-
except ApiException as e {
140-
return f"Exception occurred: {repr(e)}"
139+
except APIError as e {
140+
return f"Exception occurred: {e.error.message}"
141141
}
142142
```
143143
## Dependency changes

0 commit comments

Comments
 (0)