Optimizing Record Retrievals with Web API Conditional Retrievals | PL-400 Exam Preparation

Optimize Record Retrievals with Web API Conditional Retrievals

Question

You want to optimize the records retrievals from the Dataverse table using Web API Conditional retrievals.

What should you include in your Web API request to retrieve the record only if it is changed?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

Correct Answers: B and E

To optimize the records retrieval from the Dataverse when you use the Web API requests, you need to add an If-None-Match header with ETag value.

If data has been changed, the response returns “200 OK” HTTP status.

If there are no changes, the response returns “304 Not Modified” HTTP status.

The ETag or entity tag is the tag that OData provides with any retrieved record (Number 1)

There are two types of ETags: strong and weak validations.

The strong validation checks the resource changes on the binary level.

The weak validation checks the resource changes on a semantical level.

For the records, OData uses weak validation (Number 2).

> Key or Index Type Value

v Root 22 2 items
@odata.context A) https://cbtr1 —).crm.dynamics.com/api/data/v9.2/$metadata#contacts(fullname,emailaddress1)
Vv value =) 3items

Vv Index 0

fullname
emailaddress1 A. someone_a@example.com
contactid A) d8992291-1b9a-eb11-b1ac-002248221db9
v Index 1 z= Aitems
ay @odata.etag A. W/"677275"
fullname A_ Susanna Stubberod (sample)
emailaddress1 A someone_b@example.com
contactid A) da992291-1b9a-eb11-b1ac-002248221db9
v Index 2 z=) Aitems
@ @odata.etag A. W/"677280"
fullname A Nancy Anderson (sample)
emailaddress1 A someone_c@example.com

contactid A) dc992291-1b9a-eb11-b1ac-002248221db9

You can use the ETag to query if the record has been changed.

For that, you need to add the If-None-Match (Number 1) header with the ETag value (Number 2) to the request.

And if there are no changes, you get the “304 Not Modified” status response (Number 3)

You can also use another header, “If-Match,” with ETag value for a conditional retrieval.

GET https://cbtr ).crm.dynamics.com/api/data/v9.2/contacts(d8992291-1b9a-eb11-b1ac-002248221db9)?$select=fullname,emailaddress1 | 304 Not Modified ©

© Info Request Response hy

Headers Cookies Raw

Header Name Header Value

Authorization Bearer eyJOeXAiQiIKV1QiLCJhbGciOiJSUZI1Nilsing1dCl6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZylsimtpZCl6Im5PbzNa...
[renere:na] @D

Cookie RegClientid=ca 3a-fdf5-4aeb- 9): ARRAffinity=5bd0484c57a0d920dd2fa2a594402d78c76c193abe95...9

Host cbtr ).crm.dynamics.com

Connection close

User-Agent Paw/3.2.2 (Macintosh; OS X/10.15.7) GCDHTTPRequest

All other options are incorrect.

For more information about the Web API conditional operations, please visit the below URLs:

When using the Web API to retrieve records from a Dataverse table, you can optimize the retrieval process by using conditional retrievals. Conditional retrievals allow you to retrieve a record only if it has been changed since the last time it was retrieved, which can help to reduce network traffic and improve application performance.

To use conditional retrievals in a Web API request to retrieve a record only if it is changed, you should include the If-None-Match header in your request. The If-None-Match header is used to specify an ETag value that represents the version of the record that you last retrieved. The ETag value is a unique identifier that is generated by Dataverse and represents the current version of the record.

When you include the If-None-Match header in your Web API request, Dataverse will compare the ETag value in the header to the current ETag value for the record. If the ETag values match, Dataverse will return a 304 Not Modified status code and an empty response body, indicating that the record has not been changed since the last time it was retrieved. If the ETag values do not match, Dataverse will return the updated record in the response body, along with a new ETag value that represents the current version of the record.

The other answer choices are not relevant to using conditional retrievals for Web API requests in Dataverse. Here's a brief explanation of each answer choice:

A. Prefer - The Prefer header is used to specify preferences for the response format or behavior, such as requesting a specific content type or response format. It is not relevant to conditional retrievals.

B. ETag - The ETag header is used to represent the current version of a resource and is used in conditional requests to check if the resource has changed. This is the correct answer for this question.

C. odata.track-changes - The odata.track-changes header is used to enable or disable change tracking for a query or operation in Dataverse. It is not relevant to conditional retrievals.

D. deltatoken - The deltatoken header is used to specify a delta token value for retrieving changes to a collection of records in Dataverse. It is not relevant to conditional retrievals.

E. If-None-Match - This is the correct answer for this question. The If-None-Match header is used to specify an ETag value for a conditional retrieval request.