Server Logic in Power Pages Explained with Real Time API Example

Overview:

Power Pages is commonly used to build external websites on top of Dataverse. While it works well for forms, lists, and UI customization, handling sensitive logic and third-party APIs has always been a challenge.

Most implementations rely on client-side JavaScript, which means API URLs, keys, and request details can be exposed in the browser. This becomes risky, especially for public-facing sites.

Server Logic in Power Pages helps solve this problem by allowing developers to run business logic on the server. Instead of calling external APIs directly from the browser, the site communicates with secure server-side logic that controls the request and response. This makes integrations safer, cleaner, and easier to manage.

Why server logic?

Server Logic is designed for scenarios where client side JavaScript is not sufficient or safe. Imagine an online store built on Power Pages that handles discount calculation, inventory validation, or payment verification. If these operations are implemented on the client side, users can inspect network calls and manipulate requests. Server Logic allows these operations to run securely on the server with proper permissions. The client only receives the required response, not the implementation details.

This makes Server Logic ideal for

  • Calling paid or sensitive external APIs
  • Handling authentication tokens and secrets
  • Implementing business validations
  • Orchestrating complex workflows
  • Integrating ERP or CRM systems securely

Configure Server Logic

Before using Server Logic, it must be enabled in Power Pages. The configuration is done from Power Pages Management app. To-do so, follow the below steps

  • Open Power Pages Management
  • Navigate to Site Settings
  • Enable Server Logic feature

The site setting to be configured is in the below image.

Server Logic uses server side JavaScript that follows the ECMAScript 2023 standard. However, it does not support browser specific objects such as window, document, fetch, or XMLHttpRequest. Instead, Power Pages provides server specific objects such as Server.Connector.HttpClient, Server.Context, and Server.Logger.

Set up Server Logic

Follow these steps to create a new Server Logic in Power Pages.

  • Navigate to make.powerpages.com
  • Select your Power Pages site.
  • Open Set up from the left navigation
  • Under Integrations, select Server Logic
  • Click + New Server Logic.
  • Provide the name, description, and permissions.
  • Click Add
  • Once created, select the Server Logic and click Edit Code. This opens an in browser VS Code editor.

Inside the editor

  • Navigate to the serverlogics folder
  • Open the created server logic file
  • Modify or overwrite the default code

Demonstration

For the demonstration purpose, I will create a web page which will show the current day weather for each hour by fetching the user latitude and longitude. For that, I have used the Geolocation API for getting the latitude and longitude of the user and Open-Meteo API to get the weather data of the retrieved location. I have made the API call inside the Server Logic and call the server logic in the web page. You can find the code for the server logic below.

For me i have a separate page for the demonstration of this use-case which is under Weather folder in VS Code. You can refer the below code for calling the server logic inside a web page.

As I am based out of Chennai, the co-ordinates are in the below image

And the resultant page is like the below screenshot

My Thoughts

After working with Server Logic, it clearly feels like a much-needed improvement for Power Pages. It removes the fear of exposing sensitive data such as client secrets, tokens, or transaction details.

This is especially useful for scenarios like payment integrations, ERP connections, or secure CRM data access. Even though the feature is still in preview, it already adds strong value. With future updates like better debugging tools, Liquid support, and easier testing, Server Logic has the potential to become a core building block for secure Power Pages solutions.

References:

Tamilarasu Arunachalam

Post a Comment

Previous Post Next Post