The Enterprise Plus Edition features a REST API: This interface can be used to “address Password Safe externally” in order to, for example, read data for other programs. The REST API can only be accessed via our wrappers using C# and JavaScript.

In the JavaScript version of the API, all enums can be found under the global object “PsrApiEnums”.

Requirements and download

The API is exclusively available in the Enterprise Plus Edition. The API client for the desired programming language can be downloaded from the Customer Information System. In order to use the API, web services must have been activated on the AdminClient in the WebClient module.

Using the API

The central object is “PsrApi”. It contains various “managers” that contain the entire business logic. First a “PsrApi” object must be created. The only transfer parameter of this class is the endpoint of the Password Safe WebServices. If the WebClient is in use, “call-des-webclient/api” can be used as the endpoint. Otherwise the Password Safe Server, i.e. “ip-des-servers:11016”, must be used directly.

C#

var psrApi = new PsrApi(„passwordsafe.company.com/api“);

JavaScript

const psrApi = new PsrApi(„passwordsafe.company.com/api“)

Login

If you do not log in to the system in advance, it is not possible to use the API. The first parameter for the login method is the desired database, followed by the user name and password. It is important to note that all methods for running the API that initiate a server call are implemented asynchronously. “Task” objects are returned in C# and “Promise” objects are returned in JavaScript.

C#

await psrApi.AuthenticationManager.Login(„Company“, „username“, „password“);

JavaScript

await psrApi.authenticationManager.login(„Company“, „username“, „password“)

Methods

All methods for the API can then be used. For example, you can search for records and decrypt a password:

C#

using System;
using System.Linq;
using System.Threading.Tasks;
using PsrApi.Data;
using PsrApi.Data.Enums;


namespace CSharpSDK
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // After login you can use all functions of the API.
            // Insert your access data in the places marked with #.
            var psrApi = new PsrApi.PsrApi("#");
            await psrApi.AuthenticationManager.Login("#", "#", "#");

            // Passwords are in the context of the API container.
            // The ContainerManager is necessary for handling.
            var conMan = psrApi.ContainerManager;

            // To be able to filter for specific passwords, you need a filter of type PsrListFilterGroupContent. 
            // To do this, you need to retrieve the default filter for passwords.
            var passwordListFilter = await conMan.GetContainerListFilter(
                PsrContainerType.Password, true);

            // In a second step you can search the default filter for a filter object of type PsrListFilterGroupContent
            var contentFilter = passwordListFilter.FilterGroups
                .OfType<PsrListFilterGroupContent>().FirstOrDefault()
                ?.SearchList.FirstOrDefault();

            if (contentFilter != null)
            {
                // Replace the # digit with your search term.
                // In addition, the filter must be marked as Active.
                contentFilter.Search = "#";
                contentFilter.FilterActive = true;
            }

            // Now your searched passwords can be retrieved 
            // using the previously configured filter.
            var passwords = await conMan.GetContainerList(
                PsrContainerType.Password, passwordListFilter);

            var passwordContainer = passwords.FirstOrDefault();
            if (passwordContainer != null)
            {
                // To make your searched password visible in plain text,
                // you need to search for the first password field
                // in the list of ContainerItems in your password
                var passwordItem = passwordContainer.Items
                    .FirstOrDefault(i => i.ContainerItemType == PsrContainerItemType.ContainerItemPassword);

                // The found ContainerItem can then be decrypted.
                var decryptedPasswordString = await conMan.DecryptContainerItem(passwordItem);

                // After that you can use the password in plain text
               Console.WriteLine("Your password is: " + decryptedPasswordString);
            }

            // If the API is no longer needed,
            // you must log out of the current session again.
            await psrApi.AuthenticationManager.Logout();
        }
    }
}

JavaScript

(async function() {

  const { PsrApi, PsrApiEnums } = require('./src/psrApi')
  const { PsrContainerType, PsrContainerItemType } = PsrApiEnums

  // After login you can use all functions of the API.
  // Insert your access data in the places marked with #.
  const psrApi = new PsrApi('#')
  await psrApi.authenticationManager.login('#', '#', '#')

  // Passwords are in the context of the API container.
  // The ContainerManager is necessary for handling.
  const conMan = psrApi.containerManager

  // To be able to filter for specific passwords, you need a filter 
  // of type PsrListFilterGroupContent. 
  // To do this, you need to retrieve the default filter for passwords.
  const passwordListFilter = await conMan.getContainerListFilter(
    PsrContainerType.Password, true)

  // In a second step you can search the default filter for a filter 
  // object of type PsrListFilterGroupContent.
  const contentFilter = passwordListFilter.FilterGroups
    .find(fg => 'SearchList' in fg).SearchList[0]

  if (contentFilter) {
    // Replace the # digit with your search term.
    // In addition, the filter must be marked as Active.
    contentFilter.Search = '#'
    contentFilter.FilterActive = true
  }

  // Now your searched passwords can be retrieved 
  // using the previously configured filter.
  const passwords = await conMan.getContainerList(
    PsrContainerType.Password, passwordListFilter)

  const passwordContainer = passwords[0]
  if (passwordContainer) {
    // To make your searched password visible in plain text, 
    // you need to search for the first password field 
    // in the list of ContainerItems in your password.
    const passwordItem = passwordContainer.Items
      .find(i => i.ContainerItemType === PsrContainerItemType.ContainerItemPassword)

    // The found ContainerItem can then be decrypted.
    const decryptedPasswordString = await conMan.decryptContainerItem(passwordItem)

    // After that you can use the password in plain text.
    console.log('Your password is: ', decryptedPasswordString)
  }

  // Don't forget logout after completed work to prevent dead sessions
  await psrApi.authenticationManager.logout()

})()

Technical documentation

You can find the complete technical documentation for the API under the following link: Password Safe API

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.