Introduction

When working with APIs and data integration in Power Apps, you may come across the term ETag (Entity Tag). ETag plays a crucial role in managing data consistency, handling concurrent updates, and improving performance when interacting with data sources such as Microsoft Dataverse, SharePoint, and custom APIs.

This article explains what ETags are, why they matter, and how they are used in Power Apps.

What is an ETag?

An Entity Tag (ETag) is a unique identifier assigned to a specific version of a record or resource.

Whenever a record is modified, its ETag value changes. This allows applications to determine whether the data has been updated since it was last retrieved.

Think of an ETag as a version number for a record.

Example

Suppose a customer record has the following ETag:

{
  "CustomerID": 101,
  "Name": "Ketan",
  "@odata.etag": "W/\"123456\""
}

If another user updates the customer information, the ETag may change to:

{
  "CustomerID": 101,
  "Name": "Ketan",
  "@odata.etag": "W/\"123457\""
}

The changed ETag indicates that the record has been modified.

Why are ETags Important?

1. Prevent Data Conflicts

In multi-user environments, multiple users may edit the same record simultaneously.

Without ETags:

With ETags, the system can detect that the record has changed and prevent accidental overwrites.

2. Optimistic Concurrency Control

ETags enable optimistic concurrency.

Instead of locking records while users edit them, the system checks whether the record has changed before saving updates.

Benefits include:

3. Improve API Efficiency

ETags can reduce unnecessary data transfers.

Clients can ask:

"Only send me the resource if it has changed."

This minimizes bandwidth usage and improves application performance.

ETags in Power Apps

Power Apps often works with data sources that expose ETags through OData services.

Common examples include:

When records are retrieved, the ETag value is typically included in the response.

Example:

{
  "@odata.etag": "W/\"789654\"",
  "Title": "Project Alpha",
  "Status": "Active"
}

ETag in SharePoint Lists

When Power Apps connects to SharePoint, every list item contains an ETag value.

Example:

{
  "__metadata": {
      "etag": "\"3\""
  }
}

Whenever the list item changes:

{
  "__metadata": {
      "etag": "\"4\""
  }
}

The incremented value indicates a newer version of the item.

How Power Apps Uses ETags

Power Apps automatically uses ETags behind the scenes when updating records.

For example:

Patch(
    Customers,
    ThisItem,
    {
        Status: "Approved"
    }
)

The platform sends the ETag along with the update request to verify that the record has not changed since it was loaded.

If the ETag does not match the latest version, the update may fail with a concurrency-related error.

Handling Concurrency Errors

A common scenario:

  1. User A opens a record.

  2. User B modifies and saves it.

  3. User A attempts to save outdated information.

  4. The ETag mismatch is detected.

Possible error message:

The specified record has been modified by another user.

Recommended Handling

Use error handling functions:

IfError(
    Patch(
        Customers,
        ThisItem,
        {
            Status: "Approved"
        }
    ),
    Notify(
        "The record was updated by another user. Please refresh and try again.",
        NotificationType.Error
    )
)

This provides a better user experience.

ETags with Power Automate

When using Microsoft Power Automate, ETags can be used in HTTP actions.

Example:

If-Match: W/"123456"

The API updates the resource only if the ETag matches the current version.

Benefits

ETag and HTTP Headers

Several HTTP headers work with ETags.

HeaderPurpose
ETagReturns the current version identifier
If-MatchUpdate only if ETag matches
If-None-MatchReturn data only if changed
If-Modified-SinceCheck modification timestamp

Example:

GET /api/customers/101

Response:
ETag: "123456"

Update request:

PUT /api/customers/101
If-Match: "123456"

Best Practices

Always Handle Errors

Implement error handling using:

IfError()

or

Errors()

Refresh Before Editing

Refresh data before allowing users to edit:

Refresh(Customers)

This helps reduce concurrency conflicts.

Use Dataverse Concurrency Features

When using Dataverse:

Avoid Blind Updates

Instead of updating records without validation:

Patch(Customers, ThisItem, Updates)

Ensure users are working with the latest data whenever possible.

Common ETag-Related Errors

ErrorCause
Precondition Failed (412)ETag mismatch
Conflict (409)Concurrent modification
Record Modified by Another UserVersion changed
Update FailedStale record version

Real-World Example

Imagine a Help Desk application built in Power Apps.

A support ticket is assigned to an agent.

Without ETags:

With ETags:

This ensures reliable and accurate data management.

Conclusion

ETags are a powerful mechanism for maintaining data consistency in Power Apps and related Microsoft technologies. They help prevent accidental overwrites, support optimistic concurrency, and improve API efficiency.

Key Takeaways

Understanding ETags enables Power Apps developers to build more reliable, scalable, and user-friendly business applications.