I wanted to update you all on a breaking change that we are making to the Outlook REST API Beta endpoints. This change is the introduction of a Request Validator which is going to be deployed worldwide over the next few weeks. Here are the details of this change.
What is the Request Validator?
The Request Validator is a module that checks the validity of incoming requests based on the following
- Annotation restrictions in the Edm Model, namely
- Search
- Expand
- Navigation
- Change Tracking
- Insert
- Update – (Patch/Merge)
- Delete
- Http methods allowed for a specific resource or collection (e.g. GET, POST, PATCH/MERGE, DELETE)
Why add a Request Validator?
- To catch invalid requests early on before sending the request downstream
- To adhere to the expected behavior based on the OData Model for transparency. The Odata model uses annotations to describe its capabilities (what an app can or cannot do)
- To conform to the OData Spec on what requests are permitted for a given http method
What is the impact of introducing the Request Validator?
- Developers might need to rewrite some requests if these requests are not consistent with the model – as the request validator will throw an Exception if it fails to validate the request
- Developers can expect consistent behavior that is based on the annotation specified in the Edm model
- Developers might need to rewrite test cases for queries that fails the request validator
Exceptions
- Insert
- HttpCode: HttpStatusCode.BadRequest = 400
- StringCode: InsertNotSupported
- Message: ErrorRequestValidatorInsertNotPermitted(string propertyName) = Insert is not permitted for property ‘{0}’ according to the annotation specified in the Edm model.
- Update
- HttpCode: HttpStatusCode.BadRequest = 400
- StringCode: UpdateNotSupported
- Message: ErrorRequestValidatorUpdateNotPermitted(string propertyName) = Update is not permitted for property ‘{0}’ according to the annotation specified in the Edm model.
- Delete
- HttpCode: HttpStatusCode.BadRequest = 400
- StringCode: DeleteNotSupported
- Message: ErrorRequestValidatorDeleteNotPermitted(string propertyName) = Delete is not permitted for property ‘{0}’ according to the annotation specified in the Edm model.
- Navigation
- HttpCode: HttpStatusCode.BadRequest = 400
- StringCode: NavigationNotSupported
- Message:
- ErrorRequestValidatorNavigationNotPermitted(string propertyName) = Navigation is not permitted for property ‘{0}’ according to the annotation specified in the Edm model.
- ErrorRequestValidatorRecursiveNavigationNotPermitted(string propertyName) = Recursive navigation is not permitted after property ‘{0}’ according to the annotation specified in the Edm model.
- Search
- HttpCode: HttpStatusCode.BadRequest = 400
- StringCode: SearchNotSupported
- Message:
- ErrorRequestValidatorSearchNotPermitted(string propertyName) = Search is not permitted for property ‘{0}’ according to the annotation specified in the Edm model.
- ErrorRequestValidatorSearchNotPermittedForSegment = Only NavigationProperties and EntitySets are searchable
- Expand
- HttpCode: HttpStatusCode.BadRequest = 400
- StringCode: Â ExpandNotSupported
- Message: ErrorRequestValidatorExpandNotPermitted(string propertyName) = Expand is not permitted for property ‘{0}’ according to the annotation specified in the Edm model.
- Default
-
- Will be throwing the existing ODataResponseException with custom message
- HttpCode: HttpStatusCode.MethodNotAllowed = 405
- StringCode: ErrorInvalidRequest
- Message: ErrorRequestValidatorMethodNotAllowed(string method, string propertyName) = Method ‘{0}’ not allowed for ‘{1}’
- Will be throwing the existing ODataResponseException with custom message
Example:
1. Navigation restriction placed on a navigation property
GET  https://outlook.office.com/api/beta/me/events(‘id’)/calendars(‘id’)/events(‘id’)
This request throws an exception as Recursive navigation is not permitted after property ‘events’
Looking in the metadata for the Calendar Entity, the navigation property Events has the navigation annotation where the navigation type set as single. This means you can navigate upto https://outlook.office.com/api/beta/me/events(‘id’)/calendars(‘id’)/events but not beyond.
The following segments may be appended after the navigation property
-
-
- Count segment /$count
- Batch segment /$batch
- Value segment /$value
- Navigation property link segment /$ref
-
2. When sending invalid segment for the http method
POST https://outlook.office.com/api/beta/me/message(‘id’)
This request throws an exception as key segment is not allowed for post
http code: 405
string code: ErrorInvalidRequest
message: Method ‘POST’ not allowed for ‘Microsoft.OData.Core.UriParser.Semantic.KeySegment’
– Abdelkader Bahgat on behalf of the Outlook Ecosystem team