Server logic is the new capability in Power Pages that allows you to run JavaScript code securely on the server side.

This means you can move sensitive logic off the client, especially when working with third-party APIs, API keys, or complex data operations that shouldn’t be exposed to users.

Previously, implementing secure backend logic required using Power Automate flows or creating a custom Web API (C#) hosted in Azure. Now, with server logic, you can write and manage JavaScript directly within Power Pages itself.

Important

This feature is still in preview and should not be used in production environments.

Creating Server Logic

First, navigate to the maker portal and select your site.

Under Set up > Integrations, you will find Server logic.

server logic in maker portal

Click on New server logic.

Give your server logic a name and assign web roles to ensure only authorized users can run it.

create server logic

To edit the code of your server logic, you can select it and click on Edit code. It will open a VS Code editor instance in your browser to edit your code.

edit server logic

By default, the editor includes function templates for all HTTP methods (get, post, patch, delete, etc). You can safely remove any you don’t need.

In this example, we’ll create a simple get() method that fetches weather information from the OpenWeather API for a given location.

JavaScript
// server logic
async function get() {
    try {
 
        if (!Server.Context.QueryParameters["location"]) {
            const errorMsg = "Missing required query parameter: location";
            Server.Logger.Error(errorMsg);
            return JSON.stringify({ status: "error", method: "GET", message: errorMsg });
        }
 
        const location = Server.Context.QueryParameters["location"]; // Context reference
 
        // Get API key from settings
        const apiKey = Server.Sitesetting.Get('OpenWeather/APIKEY');

        // Call third-party API
        const response = await Server.Connector.HttpClient.GetAsync(
            `https://api.openweathermap.org/data/2.5/weather?q=${location}&units=metric&appid=${apiKey}`, 
            {
                "Content-Type":"application/json"
            }
        );
 
        return response;
    } catch (err) {
        Server.Logger.Error("GET failed: " + err.message);
        return JSON.stringify({ status: "error", method: "GET", message: err.message });
    }
}

Here, the API key is stored securely on the server as a Site Setting, and the client never sees it.

Calling server logic from the client

You can call server logic just like any other Web API endpoint in Power Pages using JavaScript.

The server logic endpoint is in the format:

https://<site-url>/_api/serverlogics/<server-logic-name>

JavaScript
// client-side code
webapi.safeAjax({
    type: 'GET',
    url: '/_api/serverlogics/GetWeather?location=' + location,
    contentType: 'application/json',
    success: function (response, textStatus, xhr) {
        let res = JSON.parse(response.data);
        
        // your client logic

    },
    error: function (xhr, textStatus, errorThrown) {
        console.log(errorThrown);
    }
});

Note

Make sure you have the wrapper function available before calling the server logic.

With Power Pages Server Logic, you can handle more work on the server and keep sensitive data secure. It’s an easy way to build faster, safer, and more maintainable web experiences right inside Power Pages without needing extra services or complex setups.

Learn more about the capability in the official documentation.