# Step-By-Step Guide
source: https://developer.mastercard.com/account-catalog-services/tutorial/api-testing/step2/index.md

### Step-By-Step Guide {#step-by-step-guide}

1. Download the API Specification and place it in a folder. **Mastercard-UniversalSpecApiClient** is the folder name being used for this tutorial.

2. Generate an API Client project.

   1. Download the OpenAPI Generator CLI. Follow the instructions here.  
   2. Create a config.json file inside the **Mastercard-UniversalSpecApiClient** folder with the following options of OpenAPI Generator:

   ```json
   {
     "groupId": "com.mycompany.app",
     "artifactId": "mastercard-universalspec-api-client",
     "artifactVersion": "1.0.0",
     "invokerPackage": "com.mycompany.app.universalspec",
     "apiPackage": " com.mycompany.app.universalspec.api",
     "modelPackage": "com.mycompany.app.universalspec.model"
   }
   ```

   3. Execute the following command inside the **Mastercard-UniversalSpecApiClient** folder to generate a client in Java language. `openapi-generator-cli generate -g java --library okhttp-gson -i *.yaml -c config.json -o mastercard-universalspec_api_client`

   <br />

3. Importing API Client project in Eclipse.

   1. Import the project in eclipse as a maven project by following the screen shots.
      Open Eclipse, right-click on the Package Explorer pane, and choose **Import** from the pop-up.
      ![](https://static.developer.mastercard.com/content/account-catalog-services/uploads/tutorials/10.png)

   2. Type **Maven** in the 'select an import wizard', select 'Existing Maven Project' from the options that appear, and click **Next** .
      ![](https://static.developer.mastercard.com/content/account-catalog-services/uploads/tutorials/11.png)

   3. Click **Browse** and navigate to the generated client project folder `mastercard-universalspec_api_client` and click **Finish** . This completes the import process of the client project in Eclipse.
      ![](https://static.developer.mastercard.com/content/account-catalog-services/uploads/tutorials/12.png)

   4. On successful import, the project in Eclipse will show up in the structure as follows.
      ![](https://static.developer.mastercard.com/content/account-catalog-services/uploads/tutorials/13.png)

   <br />

4. Add the following Mastercard client encryption and authentication libraries to the pom.xml.

   1. [Java Client Encryption Library](https://github.com/Mastercard/client-encryption-java).

   ```xml
   <dependency>
   	<groupId>com.mastercard.developer</groupId>
   	<artifactId>client-encryption</artifactId>
   	<version>${client-encryption-version}</version>
   </dependency>
   ```

   2. [Java Client Authentication Library](https://github.com/Mastercard/oauth1-signer-java).

   ```xml
   <dependency>
   	<groupId>com.mastercard.developer</groupId>
   	<artifactId>oauth1-signer</artifactId>
   	<version>${oauth1-signer-version}</version>
   </dependency>
   ```

   Note: It is recommended to use the latest release of the client encryption and authentication libraries.

   <br />

5. Configuring API client project with the keys.

   1. Place the Sandbox Consumer key (.p12 file), Sandbox client encryption key (.pem file) in src/test/resources generated during Sandbox (MTF) project creation.

   <br />

6. Call the Account Catalog Services API.

   1. Create a **UniverslSpecSubmissionApiTest** class in src/test/java. The package for this class should be the same as that of the API class.  
   2. Set the following values in the **UniverslSpecSubmissionApiTest** class.

   ```java
   // Consumer Key details
       
       String consumerKey = "<name of the .p12 file in src/test/resources>";
       String signingKeyAlias = "<key_alias of .p12 file>";
       String signingKeyPassword = "<keystore_password of .p12 file>";
       String signingKeyPkcs12FilePath = "<src/test/resources/.p12 file>";
       
   // Client Encryption Key details
       
       String encryptionCertificateFilePath = "<src/test/resources/.pem file>";                                                                          
   ```

   3. Instantiate the Consumer Key and Client Encryption key and **FieldLevelEncryption** config objects.

   ```java
   // Instantiating Consumer Key
         PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyPkcs12FilePath, signingKeyAlias, signingKeyPassword);
   //Instantiating Encryption Key
        Certificate encryptionCertificate = EncryptionUtils.loadEncryptionCertificate(encryptionCertificateFilePath);
   //Instantiating the Encryption Config for payload encryption
        FieldLevelEncryptionConfig config = FieldLevelEncryptionConfigBuilder.aFieldLevelEncryptionConfig()
        .withEncryptionCertificate(encryptionCertificate)
        .withOaepPaddingDigestAlgorithm("SHA-512")
        .withEncryptedValueFieldName("encryptedData")
        .withEncryptedKeyFieldName("encryptedKey")
        .withIvFieldName("iv")
        .withOaepPaddingDigestAlgorithmFieldName("oaepHashingAlgorithm")
        .withEncryptionKeyFingerprintFieldName("publicKeyFingerprint")
        .withFieldValueEncoding(
        FieldLevelEncryptionConfig.FieldValueEncoding.BASE64)
        .withEncryptionPath("$", "$")
        .build();
   ```

   4. Instantiate the client with interceptors for authentication and payload encryption.

   ```java
     	ApiClient client = Configuration.getDefaultApiClient();
     	client.setBasePath("https://sandbox.api.mastercard.com/asc/universal-spec");
     	client.setDebugging(true);
     	client.setHttpClient(client.getHttpClient()
     	.newBuilder()
     	.addInterceptor(new OkHttpFieldLevelEncryptionInterceptor(config))
     	.addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey))
     	.build());
     	AccountsSubmissionApi api = new AccountsSubmissionApi(client);
   ```

   5. Calling the API with test data. Refer to [API Reference](https://developer.mastercard.com/account-catalog-services/documentation/api-reference/index.md) for the attribute details.

   ```java
   //Setup test data to call the API
       String universalSpecApiRequestId = UUID.randomUUID().toString();
       RegistrationDetails registrationDetails = buildRegistrationDetails();
   //Call the API endpoint
       ApiResponse<RegistrationAcknowledgement> apiResponse =
       api.register(universalSpecApiRequestId, registrationDetails);
   //Get the response
       apiResponse.getData();
   ```

   <br />

