Skip to main content
Version: v46

API Client Integration

Use the PrivX REST API to automate administrative tasks. The roles you assign to an API client determine which tasks it can perform. To make an authenticated request, use the client credentials to obtain an access token, then include the token in your request.

You can access the PrivX REST API with any REST client that supports OAuth 2.0. The examples in this article use curl. To automate tasks with a PrivX SDK, follow the guide for your language:

For endpoint descriptions and request parameters, see PrivX API Guide.

Creating API Clients and Assigning Permissions​

To define the permissions of the API client:

  1. In the PrivX Web UI, go to Administration → Roles and click Add Role.

    1. Under Permissions, select the permissions required by your API client.
    2. If the API client needs to use this role to authenticate to target hosts over SSH, enable Use with PrivX Desktop. For REST API operations such as listing hosts, roles, or users, you can leave this disabled.
    3. Save the changes. Repeat this step if you need to create additional roles.
  2. Go to Deployment → API Clients and click Add API Client.

    1. Enter a name for the client, assign the role you created, and click Save. You can assign additional roles if needed.
    2. Back on the API clients form, expand Client Credentials for your client. You need both OAuth Client Secret and API Client Secret to request an access token. If you need TLS Trust Anchor to verify the PrivX server certificate, you can find it at the bottom of the page.

Authenticating API Requests​

After creating your API client entry, authenticate using your API client as follows:

  1. Request an access token from /auth/api/v1/oauth/token. Replace privx.example.com with your PrivX server address and <oauth_client_id>, <oauth_client_secret>, <api_client_id>, and <api_client_secret> with the values from Credentials.

    note

    The /auth/api/v1/oauth/token endpoint accepts only application/x-www-form-urlencoded request bodies. If your client sends JSON (application/json) by default, use form data for this request.

    curl -X POST \
    https://<privx.example.com>/auth/api/v1/oauth/token \
    -u <oauth_client_id>:<oauth_client_secret> \
    --data-urlencode 'grant_type=password' \
    --data-urlencode 'username=<api_client_id>' \
    --data-urlencode 'password=<api_client_secret>'

    On success, PrivX returns a JSON response similar to the following example:

    {
    "access_token": "<access_token>",
    "token_type": "bearer",
    "expires_in": 1800
    }
  2. You can now use the access token to perform PrivX actions using other endpoints.\

    Include the access token in the Authorization header of subsequent requests. For example, to list hosts, run the following command. Replace <access_token> with the access_token value from the response and privx.example.com with your PrivX server address.

    $ curl -X GET \
    -H "Authorization: Bearer <access_token>" \
    https://<privx.example.com>/host-store/api/v1/hosts