Skip to main content

15.1.2 Quick Start

Prerequisites

Complete Installation first. This guide takes about 5 minutes and walks you through your first API call.

Goal

By the end of this page you will be able to:

  1. Log in with a username and password to obtain an access token
  2. Use the token to query the element list

Step 1 — Configure the Connection

Store the server address and credentials in environment variables to avoid hardcoding secrets in source code:

export IDMP_HOST=http://localhost:6042   # replace with your IDMP server address
export IDMP_USERNAME=your_username
export IDMP_PASSWORD=your_password

Step 2 — Log In and Obtain a Token

import org.openapitools.client.ApiClient;
import org.openapitools.client.api.UserResourceApi;
import org.openapitools.client.model.LoginReqDTO;
import org.openapitools.client.model.LoginRspDTO;

// 1. Create a client configured for Bearer Token authentication
ApiClient apiClient = new ApiClient("Authorization");
apiClient.setBasePath(System.getenv("IDMP_HOST"));

// 2. Log in and retrieve the token
UserResourceApi userApi = apiClient.buildClient(UserResourceApi.class);
LoginReqDTO loginReq = new LoginReqDTO();
loginReq.setLoginName(System.getenv("IDMP_USERNAME"));
loginReq.setPassword(System.getenv("IDMP_PASSWORD"));

LoginRspDTO loginRsp = userApi.apiV1UsersLoginPost(loginReq);
String token = loginRsp.getToken();
System.out.println("Logged in. Token: " + token);

// 3. Set the token on the client — all subsequent requests include it automatically
apiClient.setBearerToken(token);

Step 3 — Query the Element List

import org.openapitools.client.api.ElementResourceApi;
import org.openapitools.client.api.ElementResourceApi.ApiV1ElementsGetQueryParams;
import org.openapitools.client.model.PageOfBasicElementDTO;

// Continuing from Step 2 — apiClient already has the token set
ElementResourceApi elementApi = apiClient.buildClient(ElementResourceApi.class);
ApiV1ElementsGetQueryParams queryParams = new ApiV1ElementsGetQueryParams();
PageOfBasicElementDTO elements = elementApi.apiV1ElementsGet(queryParams);

System.out.println("Elements: " + elements);

Next Steps