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:
-
In the PrivX Web UI, go to Administration → Roles and click Add Role.
- Under Permissions, select the permissions required by your API client.
- 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.
- Save the changes. Repeat this step if you need to create additional roles.
-
Go to Deployment → API Clients and click Add API Client.
- Enter a name for the client, assign the role you created, and click Save. You can assign additional roles if needed.
- 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:
-
Request an access token from
/auth/api/v1/oauth/token. Replaceprivx.example.comwith your PrivX server address and<oauth_client_id>,<oauth_client_secret>,<api_client_id>, and<api_client_secret>with the values from Credentials.noteThe
/auth/api/v1/oauth/tokenendpoint accepts onlyapplication/x-www-form-urlencodedrequest 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} -
You can now use the access token to perform PrivX actions using other endpoints.\
Include the access token in the
Authorizationheader of subsequent requests. For example, to list hosts, run the following command. Replace<access_token>with theaccess_tokenvalue from the response andprivx.example.comwith your PrivX server address.$ curl -X GET \-H "Authorization: Bearer <access_token>" \https://<privx.example.com>/host-store/api/v1/hosts