REST API Usage in EDB Postgres Enterprise Manager (PEM)

September 26, 2023


One of the standout features of EDB Postgres Enterprise Manager (PEM) is the REST API, which offers efficient data reading and writing capabilities, as well as access to various functionalities without the need to log in to the PEM UI. This blog will guide you through the process of utilizing the REST API in PEM for streamlined database management.

Note that for all the examples, we assume that you are working on the machine where PEM is installed. In a production cluster, this is unlikely to be the case and you should replace `` with the network address of your PEM server.

Accessing Swagger Editor

To start your journey, you need to access the REST API documentation via the following URL:

This documentation, presented through the Swagger Editor, serves as a reference point for understanding the available API endpoints and their functionalities.

Accessing the Endpoints:

Token-Based Authentication

Security is a top priority, and PEM ensures it through a token-based authentication mechanism for accessing its REST APIs. This authentication method not only secures your interactions but also simplifies exploration of the APIs without requiring UI login.

Step-by-Step Guide:

Let's dive into the step-by-step process of using the REST API in PEM:

1.Token Generation:

The initial step involves generating a token for authentication. To achieve this, follow these instructions:

  • Make a POST request to `` with the following information:
    • Headers: `accept: application/json`, `Content-Type: application/json`
    • Request body: `{"username":"pemuser","password":"xyz"}`
  • Retrieve the token from the `X-Subject-Token` field in the response.
  • Example to generate token: Let, Username: pemuser and Password: xyz


curl -iX POST "" -H "accept: application/json"
-H "Content-Type: application/json" -d


Copy the token from X-Subject-Token.

2.Accessing the v9/server/{server_id} endpoint:

The latest version PEM API, v9, offers the most up-to-date features and improvements.

The `v9/server/{server_id}` endpoint is a powerful space within the REST API. As an example, let's look at changing the password of a server:

  • Utilize the token obtained from Step 1.
    • “server_id” is by default 1 for pem server but to fetch the server id of other servers, the command below can be executed:
curl -iX POST "" -H "accept: application/json"
application/json" -H "X-Auth-Token: 72e3ec07-1e15-46c8-a4d9-96ebff029a7d"
  • Execute a PUT request to `` with the following headers:
    • `accept: */*`
    •  `X-Auth-Token: `
    • `Content-Type: application/json`
  • In the request body, provide the new password: `{"asb_password":"new_password"}`.
curl --insecure -X PUT "" -H "accept:
*/*" -H "X-Auth-Token: 72e3ec07-1e15-46c8-a4d9-96ebff029a7d" -H "Content-Type:
application/json" -d "{\"asb_password\":\"postgres\"}"

This command will change the password of the specified server (server with ID 1 in this case).

In conclusion, EDB Postgres Enterprise Manager's REST API offers a powerful and efficient way to manage databases. By following the steps outlined above, you can navigate the API's capabilities, authenticate securely and perform operations. Harness the power of the PEM REST API to enhance your database management experience.

In addition to the steps mentioned above, let’s explore a practical example of how to achieve server password change using Python and the requests module. This approach adds hands-on experience to the theoretical understanding we’ve discussed.

# requests library provides a simple API for interacting with HTTP operations
# such as GET , POST , PUT etc
import requests

# suppress ssl warnings

requests.packages.urllib3.disable_warnings( )

# Step 1: Token Generation

def generate_token(username, password):
  url = ""
  headers = {
    "accept": "application/json",
    "Content-Type": "application/json"
  data = {
    "username" :username,
    "password" password
  response =, headers=headers, json=data, verify=False)

# extracting the token from the response

token = response.headers["X-Subject-Token"]
return token

# Step 2: Changing Server Password

def change_server_password(token, server_id, new_password):
  url = f"{server_id}""
  headers = {
    "accept": "*/",
    "X-Auth-Token": token,
    "Content-Type": "application/json"
  data = {
    "asb_password"": new_password
  response = requests.put(url, headers=headers, json=data, verify=False)
  return response.status_code

# Main Execution

if __name__ == "__main__":

# taking user input through cmd

username = input ("Enter PEM User Username: ")

# You can also use getpass for hidden input

password = input("Enter PEM User Password: ")
token = generate_token(username, password)
status_code = change_server_password(token, server_id, new_password)

if status_code == 200:
  print("Server password changed successfully!")
  print("Server password change failed.")

Handling HTTPS Requests with SSL

In the scenarios mentioned above, we employed token-based authentication for HTTPS requests and used the --insecure flag to disable SSL verification. However, in many cases, SSL verification is crucial. Let's explore what to do in such situations.

1. Provide a Client Certificate

--cert Option

Your client certificate identifies you to the server and is crucial for authentication. To provide your client certificate, use the --cert option:

curl --cert client.crt

2. Include the Private Key

--key Option

To authenticate using your client certificate, you need to include the private key associated with it. Use the --key option for this:

curl --cert client.crt --key client.key

3. Handling Intermediate CAs

--cacert Option

If the server's certificate is signed by an intermediate CA (Certificate Authority) or isn't in your system's trusted CA list, include the CA certificate file using the --cacert option. This ensures that certificate chain validation works correctly:

curl --cert client.crt --key client.key --cacert ca.crt

Here's a Python code snippet demonstrating how to make an HTTPS request while utilizing SSL verification:

import requests

# Define the URL of the HTTPS endpoint

url = ''

# Specify the path to your trusted Certificate Authority (CA) certificate

ca_cert_file = '/path/to/ca.crt'

# Specify your client certificate and private key (if required)

client_cert = ('/path/to/client_certificate.crt', '/path/to/client_private_key.key')

# Create a session with custom SSL settings

session = requests.Session( )

# Configure SSL certificate verification

session.verify = ca_cert_file

# If client certificate and private key are needed,  provide them

if client_cert[0] and client_cert[1]:

session.cert = client_cert

# Define headers or authentication tokens as needed

headers = {
  'Authorization': 'Bearer YourToken'

# Make an HTTPS GET request

response = session.get(url, headers=headers)

# Check the response

if response.status_code == 200:
  print ('Request was successful!')
  print ('Response:', response.text)
  print ('Request failed with status code:', response.status_code)

I hope you found these tips helpful for utilizing the REST API in Postgres Enterprise Manager for streamlined database management! You can learn more about the features and functionality in PEM in our documents and release notes.  If you’re new to PEM, you can  get a high level overview here.

Share this

Relevant Blogs

The limitations of LLMs, or why are we doing RAG?

Despite powerful capabilities with many tasks, Large Language Models (LLMs) are not know-it-alls. If you've used ChatGPT or other models, you'll have experienced how they can’t reasonably answer questions about...
June 17, 2024

Finding memory leaks in Postgres C code

I spent the last week looking for a memory leak in Postgres’s WAL Sender process. I spent a few days getting more acquainted with Valgrind and gcc/clang sanitizers, but ultimately...
March 27, 2024

More Blogs

Let's Workshop an Unplanned Postgres Outage

Nobody likes it when their database goes down for any reason, especially if it was unintentional. Sometimes companies are open about their experiences and provide post-mortems for the world to...
July 07, 2023