Configure the Web API URL

There are several ways to configure the Web API URL for a client app:

  1. Method 1: Configure the Web API URL in the IDE > PowerServer painter (before build & deploy).

  2. Method 2: Configure the Web API URL in the client app > apprun.json file (after build & deploy).

  3. Method 3: Configure the Web API URL via the SetPowerServerURL function at runtime.

    Method 3 has higher priority than Method 2 and Method 1.

Method 1:

If you have specified the site URL when configuring the server profile or creating the package, the site URL will be used as the Web API URL.

  • For Local Kestrel server, the Web API site URL is automatically generated based on the host name, port number, and connection method of the Kestrel server, for example, http://localhost:5099/.


  • For IIS (local or remote), if you know where the Web APIs will be running, you can specify the site URL in the server profile; and the Web API site URL will be the same as the site URL, for example, http://localhost. If you are not sure where the Web APIs will be running, you can leave the site URL empty and specify the Web API URL later in the apprun.json file.


  • For Folder, if you know where the Web APIs will be running, you can specify the URL in the field; if you are not sure where the Web APIs will be running, you can leave the field empty and specify the URL later in the apprun.json file.


Method 2:

If you have not specified the URL in the painter, or if the client app and the PowerServer Web APIs are hosted separately in different sites or sub-folders, you can configure or change the Web API URL for the client app in the apprun.json file.

To change the Web API URL for an application:

  1. Go to the server root > [appname] folder (named after the App name configured in IDE, for example "salesdemo_cloud") which contains the application files.

  2. Open the apprun.json file in a text editor and change the Web API URL (and the launcher URL and runtime URL if necessary).

    {
        "deployment_urls": {
            "launcher": "CloudAppPublisher/CloudAppInstall 22.0",
            "runtime": "CloudAppPublisher/runtime/22.1.0.2670",
            "web_api": "http://localhost:5099"
        }
    }

Method 3:

You can also get and set the Web API URL via scripts at runtime.

To get the Web API URL using the GetPowerServerURL function:

String ls_ServerURL
ls_ServerURL = GetApplication().GetPowerServerURL() //gets the root URL, e.g. http://172.25.100.32:5000

To set the Web API URL using the SetPowerServerURL function:

String strURL
strURL = string("https://www.example.com/salesapi")
GetApplication().SetPowerServerURL(strURL)
//Creates the session manually
GetApplication().BeginSession()

Note that

1) After you set the URL via SetPowerServerURL, you must manually create the session via BeginSession, which means the "Dynamic session parameters" option in the Application property dialog must be selected.

2) And after the session is created via BeginSession, the URL cannot be changed by SetPowerServerURL anymore until the session is ended. For more information, refer to SetPowerServerURL.

Tip

When the Web APIs is running, you can run the following URLs:

  • To check the health status of Web APIs, run [Web-API-URL]/health-ui, for example, http://localhost:5099/health-ui/. (Read more)

  • To view which application(s) deployed against the current Web APIs, run [Web-API-URL]/api/Application/LoadAll, for example, http://localhost:5099/api/Application/LoadAll/. (Read more)