Power Pages Web API – Full Explanation & CRUD Operations

Power Pages Web API – Full Explanation & CRUD Operations

A complete overview of how the Web API works in Power Pages, how to enable it, how security works, and how to perform Create, Read, Update, and Delete operations on Dataverse records.

What Is the Power Pages Web API?

The Power Pages Web API allows you to interact with Dataverse data directly from your website using JavaScript or client-side code. It works similar to standard REST APIs and supports Create, Read, Update, and Delete (CRUD) operations.

It enables developers to build modern, interactive, dynamic features in Power Pages without relying only on out-of-the-box forms and lists. Web API calls work securely and respect Dataverse permissions.

Key Capabilities

  • Perform CRUD operations on Dataverse tables
  • Build custom UI components with real-time data
  • Use JavaScript on pages to fetch or update data
  • Securely interact with Dataverse using the logged-in user context

Requirements to Use the Web API

To use Web API in Power Pages, the following must be configured:

  • Web API must be enabled using Site Settings
  • Each table must explicitly allow Web API access
  • Fields must be whitelisted for API access
  • The user must have proper Table Permissions
  • A valid CSRF token must be added to requests

Important Site Settings

  • Webapi/Enabled = true
  • Webapi/tablename/enabled = true
  • Webapi/tablename/fields → List of allowed fields
  • Webapi/error/innererror → Optional for debugging

How Security Works

Web API calls follow the same security model as Power Pages:

  • The logged-in user's Web Roles determine access
  • Table Permissions control which CRUD operations are allowed
  • CSRF tokens protect the API from unauthorized requests
  • Anonymous users must be explicitly granted permissions

If a user does not have permission for a specific table or operation, the API request will fail even if the request itself is valid.

CRUD Operations Using the Web API

1. Create (POST)

Use POST to create new Dataverse records. The endpoint uses the table's plural name:

POST /_api/accounts
{
  "name": "New Account",
  "telephone1": "9876543210"
}
    

The response includes the record ID of the newly created row.

2. Read (GET)

Use GET to retrieve Dataverse data. You can retrieve all records or filter using OData:

GET /_api/accounts
GET /_api/accounts?$select=name,telephone1
GET /_api/accounts?$filter=name eq 'Contoso'
    

3. Update (PATCH)

To update a specific record, include its GUID in the URL:

PATCH /_api/accounts(00000000-1111-2222-3333-444444444444)
{
  "telephone1": "9999999999"
}
    

Only fields listed in the Web API fields configuration can be updated.

4. Delete (DELETE)

Use DELETE to remove a Dataverse record permanently:

DELETE /_api/accounts(00000000-1111-2222-3333-444444444444)
    

The table permission must explicitly allow Delete; otherwise, the API call will fail.

Important Notes & Best Practices

  • Always test CRUD actions as a user with correct Web Roles.
  • Use browser DevTools to debug API errors via the network tab.
  • Use table permissions to strictly control what anonymous users can do.
  • Enable only the fields you need - do not expose unnecessary fields.
  • Use PATCH instead of PUT for updates (Dataverse supports PATCH only).
  • Always include a valid CSRF token in headers when sending POST, PATCH, DELETE.

Comments

Popular posts from this blog

Part 1: Creating Code Apps in Power Apps - A step-by-step guide (with real errors I faced & how I fixed them)

Calling Microsoft Graph API from Power Automate Using Azure App Services – Step-by-Step Guide

Step-by-Step Guide: Power Automate Custom Connector Using Graph API from Azure App Service