--- title: "Gainsight PX Java SDK" slug: "gainsight-px-java-sdk" updated: 2026-11-23T12:30:28Z published: 2026-11-23T12:30:28Z canonical: "support.gainsight.com/gainsight-px-java-sdk" --- > ## Documentation Index > Fetch the complete documentation index at: https://support.gainsight.com/llms.txt > Use this file to discover all available pages before exploring further. # Gainsight PX Java SDK This article explains how to use Gainsight PX’s Java Software Development Kit (SDK). ## Overview Gainsight PX Java SDK is a powerful collection of APIs that allows you to perform various tasks. You can use this SDK to create, read, update, or delete User and Account records. This SDK also provides APIs to view, launch, and pause engagements. ## Download You can download the SDK client from the following locations, based on the version: - [Java 8](https://github.com/aptrinsic/px-java-sdk/blob/main/px-java-sdk-1.1.jar) - [Java 17](https://github.com/aptrinsic/px-java-sdk/blob/main/java-sdk-2.0.2.jar) For more information, refer to the [*Gainsight PX REST API*](https://px-apidocs.gainsight.com/) article. ## Create PX REST API Key The Java SDK needs a PX REST API key to work. You must create a REST Key that can be used in the SDK. To create a REST API Key: 1. Navigate to **Administration** > **REST API**. 2. Click **New API Key**. 3. Create a name for the key by modifying the existing name. 4. Select the required checkboxes under the **API Permissions** section. 5. Click **Create & View**. [Embedded content](https://player.vimeo.com/video/482961446) **IMPORTANT**: Once the Key is generated, store it securely. This key is never displayed again. ![API Key.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/API_Key.png?sv=2026-02-06&spr=https&st=2026-11-24T18%3A03%3A47Z&se=2026-11-24T19%3A03%3A47Z&sr=b&sp=r&sig=yYenjroa5b6y0b0yaNgyV1IHTy0bq6IAQXrL%2Fga9tAg%3D) ## Initialize You must use the following code to initialize Gainsight PX. ```plaintext GainsightPXClient px = GainsightPXClient.builder()                    .apiToken("{apiKey}")                    .build(); ``` Replace the *{apikey}* with the key generated in the previous section. ## Handle Response Object When you execute a call via the client, you receive a PX Response object. In this code example, you can see how to extract the response-code (Status: 200), the response message, and the response object. ```plaintext PXResponse userResponse = gainsightPXClient.getUser(identifyId).join(); int responseStatus = userResponse.getStatus(); String responseMessage = userResponse.getMessage(); User user = userResponse.getResponse() ``` An Example to fetch users by their attributes is shown below: ```plaintext gainsightPXClient.getUser(identifyId).thenAccept(userResponse -> { int responseStatus = userResponse.getStatus(); String responseMessage = userResponse.getMessage(); User user = userResponse.getResponse(); // process user here... }); ``` ## Users You can use the Users API to create, read, update, and delete the User records. The following code can be used to get User details by Identify ID: ```plaintext PXResponse userResponse = gainsightPXClient.getUser(identifyId).join( User user = userResponse.getResponse(); ``` The following example shows how to fetch users by custom attributes, location and user-agent: ```plaintext Filter filter =  new Filter() .addExactMatchCondition("location.cityName", "Portland") .addExactMatchCondition("lastVisitedUserAgentData.userAgent.browserType", "firefox"); gainsightPXClient.getUsers(filter).thenAccept(usersPageResponse -> {  UsersPage usersPage = usersPageResponse.getResponse();  // the number of users that match the filter  long totalHits = usersPage.getTotalHits();  // the scrollId in case we want to get the next page  String scrollId = usersPage.getScrollId();  List users = usersPage.getUsers();  // process users here... }); ``` The following code shows how to fetch the next set of users page, by scroll ID: ```plaintext String scrollId = "{{scrollId}}" // the scrollId from the getUsers request. gainsightPXClient.getUsersNextPage.thenAccept(usersPageResponse -> {  UsersPage usersPage = usersPageResponse.getResponse();  List users = usersPage.getUsers();  // process users here... }); ``` The following code shows how to create a User: ```plaintext User user = User.builder()      .identifyId("12345678")      .firstName("john")      .lastName("johnson")      .build(); gainsightPXClient.createUser(user); ``` The following example shows how to update a user by IdentifyId: ```plaintext String identifyId = "{{userIdentifyId}}" // The user’s identifyId User user = User.builder() .firstName("john") .lastName("johnson") .build(); gainsightPXClient.updateUser(identifyId, user); ``` The following example shows how to delete a user by identifyId: ```plaintext String identifyId = "{{userIdentifyId}}"// The user's identifyId gainsightPXClient.deleteUser(identifyId); ``` ## Accounts You can use the Account API to create, read, update, and delete the User records. The following code can be used to get an account by Account ID: ```plaintext PXResponse userResponse = gainsightPXClient.getAccount(accountId).join(); Account account = userResponse.getResponse(); ``` This section explains various API functions that can be applied to create, edit or delete data related to accounts. The following example shows how to create an Account: ```plaintext Account account = Account.builder()      .id("12345678")      .name("Google")      .build(); gainsightPXClient.createAccount(account); ``` The following code shows how to Update an account: ```plaintext Account account = Account.builder()      .name("Google+")      .industry("Internet")      .build(); gainsightPXClient.updateAccount("{{accountId}}", account); ``` The following example shows how to Delete an account: ```plaintext String accountId = "{{accountId}}"; gainsightPXClient.deleteAccount(accountId); ``` The following example shows how to fetch accounts data: ```plaintext Filter filter =  new Filter() .addGreaterThanCondition("numberOfEmployees", "25"); gainsightPXClient.getAccounts(filter).thenAccept(accountsPageResponse -> {  AccountsPage accountsPage = accountsPageResponse.getResponse();  // the number of accounts that match the filter  long totalHits = accountsPage.getTotalHits();  // the scrollId in case we want to get the next page  String scrollId = accountsPage.getScrollId();  List accounts = accountsPage.getAccounts();  // process accounts here... }); ``` The following example shows how to fetch the next accounts page by scrollId: ```plaintext String scrollId = "{{scrollId}}" // the scrollId from the getAccounts request. gainsightPXClient.getAccountsNextPage.thenAccept(accountsPageResponse -> {  AccountsPage accountsPage = accountsPageResponse.getResponse();  List accounts = accountsPage.getAccounts();  // process accounts here... }); ``` ## Custom Event Sending custom events ```plaintext });public static void main(String[] args) {        String apiKey = null;    if (args.length != 1) {      System.err.println("Usage: TestSDK [REST API KEY] not passed, hardcoding API key");      apiKey = hardcodedapiKey;    } else {            apiKey = args[0];        }    GainsightPXClient px = null;    try {      px = GainsightPXClient.builder()        .apiToken(apiKey)        .baseUrl("https://api.aptrinsic.com")        .build();      // create a new Custom Event      //attributes      Map attribs = new HashMap();      attribs.put("prop1", "Red");      attribs.put("prop2", "Green");      attribs.put("prop3", "Blue");      attribs.put("prop4", "White");      CustomEvent ce = CustomEvent.builder()              .identifyId("xxxxxxx")              .eventName("Test Java API Custom Event")              .propertyKey("AP-XXXXXXXXXX-2")              .eventType("CUSTOM")              .userType("USER")              .attributes(attribs)              .build();      System.out.println("Creating Custom Event:"+ce.getEventName());      px.sendCustomEvent(ce).get();      System.out.println("Done");    } catch (IOException | QueueOverFlowException e) {      throw new RuntimeException(e);    } catch (ExecutionException e) {      throw new RuntimeException(e);    } catch (InterruptedException e) {      throw new RuntimeException(e);    }    finally {      if (px != null) {        try {          px.close();        } catch (IOException e) {          throw new RuntimeException(e);        }      }    }  } ``` ## Engagements The engagements API allows you to perform various tasks via APIs. The following code shows how to get engagement by ID: ```plaintext PXResponse engagementResponse = gainsightPXClient.getEngagement(engagementId).join(); ``` The following code shows how to launch an engagement: ```plaintext PXResponse engagementStateResponse = gainsightPXClient.startEngagement(engagementId).join(); ``` The following code shows how to launch an engagement in a specific environment: ```plaintext PXResponse engagementStateResponse = gainsightPXClient.startEngagement(engagementId, Environment.STAGE).join(); ``` The following code shows how to launch an engagement to multiple environments: ```plaintext PXResponse engagementStateResponse = gainsightPXClient.startEngagement(engagementId, Arrays.asList(Environment.STAGE, Environment.QA)).join(); ``` The following code shows how to pause an engagement: ```plaintext PXResponse engagementStateResponse = gainsightPXClient.pauseEngagement(engagementId).join(); ``` The following example shows how to get a list of engagements: ```plaintext Set contentTypes = Collections.singleton(ContentTypeOuterClass.ContentType.IN_APP_DIALOG); gainsightPXClient.getEngagements(0, 10, contentTypes).thenAccept(engagementsPageResponse -> {  EngagementsPage engagementsPage = engagementsPageResponse.getResponse();  List engagements = engagementsPage.getEngagements();  // process the engagements here }); ```