← All articles

Disconnect the REST API from the company file

While the REST API is connected to a company file, it holds the file open through the Sage 50 SDK. Sage 50 can then only open the file in multi-user mode. Some tasks need single-user mode, such as a backup, a data check or a period-end procedure. To run them, disconnect the REST API from the company file first.

Disconnecting is safe. The REST API reconnects by itself the next time a request comes in, so you do not need to reconfigure anything afterwards.

Choose a method

Method Best for
Call the Close endpoint with PowerShell A quick, repeatable disconnect you can copy and paste
Use Swagger Clicking through a page, without typing a command
Stop the IIS site Making sure nothing can reconnect while you work
Ask the MCP server Disconnecting from an AI client, in plain language

Method 1: Call the Close endpoint with PowerShell

The POST /api/database/close endpoint closes the connection to the company file. See Close database connection in the API reference.

Open PowerShell on a machine that can reach the REST API and run the script below. Replace the two values at the top with your own.

$baseUrl = "http://localhost/Sage50RestApi"
$apiKey  = "YOUR_API_KEY"

Invoke-RestMethod -Method Post `
  -Uri "$baseUrl/api/database/close" `
  -Headers @{ "x-api-key" = $apiKey }

A successful call returns isConnectionOpen set to False:

isConnectionOpen
----------------
           False

You can now open the company file in Sage 50 in single-user mode.

The URL must be reachable

The script must be able to reach the REST API at $baseUrl.

If the call returns 401, the API key is wrong. If the call cannot connect, the URL is wrong or the site is stopped.

Method 2: Use Swagger

Swagger is a web page included with the REST API where you can call any endpoint from your browser. You can use it from the server or from any other machine, as long as the REST API URL is reachable from your browser.

  1. Open a browser and go to the Swagger page of your installation, for example http://localhost/Sage50RestApi/. From another machine, replace localhost with the server name or address.
  2. In the API key box at the top, enter your API key, then click Explore.
Swagger UI header with the address box, the API key box and the Explore button, above the list of endpoint groups.
Enter your API key and click Explore.
  1. Find the Database section and click it to expand it.
  2. Click POST /api/database/close, then click Try it out.
Swagger UI Database section with the POST /api/database/close operation expanded, showing its description, response codes and the Try it out button.
Open POST /api/database/close and click Try it out.

The response shows "isConnectionOpen": false once the connection is closed.

Method 3: Stop the IIS site

Stopping the IIS website that hosts the REST API disconnects it for as long as the site is stopped. Nothing can reconnect, because no request reaches the API. Unlike the other methods, this one must be done locally on the machine that hosts the REST API.

  1. Sign in to the server, for example through Remote Desktop, and open Internet Information Services (IIS) Manager.
  2. In the Connections pane, expand Sites and select the website that hosts the REST API, for example Default Web Site.
  3. In the Actions pane, under Manage Website, click Stop.
IIS Manager with Default Web Site selected and the pointer on Stop under Manage Website in the Actions pane.
Select the website and click Stop under Manage Website.

If other applications share the same IIS website, they stop too. In that case, prefer Method 1, 2 or 4.

Method 4: Ask the MCP server

If you connected an AI client to Sage 50, you can ask it to disconnect. The client calls the MCP server, which closes the connection to the company file. You can do this from any machine where the client runs.

Type a request like this one:

The reply above is an example. The wording of your AI client’s reply will differ.

After you disconnect

The REST API does not stay disconnected on its own. The next request from any app or AI client opens the connection again, and Sage 50 may then be unable to open the company file in single-user mode.

To check whether the REST API is connected, call GET /api/database. It returns isConnectionOpen.

Next steps