Symptom
Below are few commonly asked questions and their answers on Etag used in Odata Services.
Environment
SAP Hybris Cloud for Customer
Resolution
1.What is Etag?
An Etag (entity tag) is an HTTP response header returned by an HTTP/1.1 compliant web server used to determine change in content of a resource at a given URL. The value of the header is an opaque string representing the state of the resource at the time the response was generate. Etag, basically is a timestamp which records the last change.
2.Can E-tag be used to filter the Data?
ETag is only meant for calculating ETag header for concurrency control. Hence, ETag has been made filterable=false from 1811 onwards for all new services including c4codataapi and new custom OData services. In case, you need to filter on LastChangedOn property on any entity set (Collection), you could check for a similar attribute e.g. ChangedOn, LastChangedOn, LastUpdatedOn on the header entity type and do a $expand query to get the required data.
Please note that, usually, "ChangedOn" is not specific to an entity type but is same across BO i.e. value would be the same for all entity types which are based on the BO. Hence, you could simply filter on the header and expand to the required collection via navigation.
3.What is the format for using filter in E-tag?
https://<Tenant URL>/sap/c4c/odata/v1/customer/CorporateAccountCollection?$filter=Etag eq datetimeoffset'YYYY-MM-DDT00:00:00.0000000Z'
4.How to check, if E-tag is filterable or not?
You can use the E-tag to filter the data, only if the Filterable property of E-tag is equal to ‘True’.
It can be verified by checking the metadata of the Object.
5. How to filter based on last changed time, if E-tag is not available?
You need to Create custom services on relevant BOs and add LastChangedDateTime as a property. This way relevant ObjectIDs of the headers can be retrieved using $filter on the LastChangedDateTime property and these ObjectIDs can be used as filters in standard API e.g. c4codataapi.
https://<Tenant URL>/sap/c4c/odata/v1/customer/CorporateAccountCollection?$filter=ChangedOn eq datetimeoffset'YYYY-MM-DDT00:00:00.0000000Z'
See Also
2691333 - ETags in OData with C4C
2789959 - How to query delta change through OData API
2325562 - Frequently Asked Questions on OData Services
Keywords
Odata, E-tag, LastChangedDateTime, ChangedOn, DataWorkbench