# Generate and Configure a Mastercard API Client
source: https://developer.mastercard.com/unified-installments/documentation/generating-and-configuring-a-mastercard-api-client/index.md

###### TIME TO COMPLETE: 20 MINUTES

## Overview {#overview}

In this tutorial, we will explain how to generate a simple API client for the *Mastercard Installments API*. We will walk through the steps to enable authentication.

You will learn how to:

* Generate an API client using [OpenAPI Generator](https://openapi-generator.tech/), which provides generators and library templates for supporting multiple languages and frameworks
* Integrate with our client libraries to sign requests
* Integrate with the Mastercard Installments Service APIs   

**Language used in this tutorial**: Java

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

### Step 1: Create an API Project {#step-1-create-an-api-project}

Refer to the [Create a New API Project](https://developer.mastercard.com/unified-installments/tutorial/create-project/index.md) tutorial to get access to the Sandbox environment by creating a new Mastercard Installments API project.
Note: Well done! You have now created a developer project and received credentials for your application.

### Step 2: Download the OpenAPI Specification {#step-2-download-the-openapi-specification}

1. Open the Mastercard Installments [Swagger UI](https://developer.mastercard.com/unified-installments/documentation/api-reference/apis/index.md#apis)
2. Click "*Open Specification* ": ![](https://static.developer.mastercard.com/content/unified-installments/uploads/Tutorials/open-specs.PNG)

### Step 3: Create a Maven Project {#step-3-create-a-maven-project}

To create a Maven project:

1. Create a Maven project using the IntelliJ IDEA IDE, which sets your directory structure automatically.
2. Provide an ArtifactId and a Project name as per your choice.

![](https://static.developer.mastercard.com/content/unified-installments/uploads/Tutorials/new-project.png)

### Step 4: Add Resources {#step-4-add-resources}

To add resources:

1. Add the Mastercard Installments Open API specification to your Maven project resources folder.
2. Add the generated Sandbox key (.p12 file) to your Maven project resources folder. The .p12 file is generated while creating your project on Mastercard Developers.

Your Maven project directory structure should appear as shown in the below screen shot:

![](https://static.developer.mastercard.com/content/unified-installments/uploads/Tutorials/add-resources.png)

### Step 5: Update pom.xml file {#step-5-update-pomxml-file}

To update pom.xml file:

In your IDE, add the [OpenAPI Generator maven plugin](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin) to your project pom.xml file using the below Plugin configurations:

```xml
<plugins>
    <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>5.4.0</version>
        <executions>
            <execution>
                <id>BNPL REST API Client</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/merchant-participation-api-swagger.yml</inputSpec>
                    <generatorName>java</generatorName>
                    <generateApiTests>false</generateApiTests>
                    <generateModelTests>false</generateModelTests>
                    <configOptions>
                        <sourceFolder>src/gen/java/main</sourceFolder>
                        <hideGenerationTimestamp>true</hideGenerationTimestamp>
                        <dateLibrary>java8</dateLibrary>
                    </configOptions>
                    <typeMappings>
                        <typeMapping>Date=LocalDate</typeMapping>
                    </typeMappings>
                </configuration>
            </execution>
        </executions>
    </plugin>
```

Note: The [OpenAPI Generator](https://openapi-generator.tech/) generates API client libraries using OpenAPI Specification. It provides multiple generators and library templates to support multiple languages and frameworks. We will be using the java generator for this project.

Add the following dependencies to your pom.xml file:

```xml
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.7.1</version>
	<relativePath/>
	<!-- lookup parent from repository -->
</parent>
<properties>
	<java.version>11</java.version>
	<oauth1-signer-version>1.5.2</oauth1-signer-version>
	<okhttp-version>4.9.1</okhttp-version>
	<gson-version>2.9.0</gson-version>
	<gson-fire-version>1.8.5</gson-fire-version>
	<swagger-core-version>1.6.6</swagger-core-version>
	<javax-annotation-version>1.3.2</javax-annotation-version>
	<commons-lang3-version>3.11</commons-lang3-version>
</properties>
<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	<dependency>
		<groupId>org.projectlombok</groupId>
		<artifactId>lombok</artifactId>
		<optional>true</optional>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>com.mastercard.developer</groupId>
		<artifactId>oauth1-signer</artifactId>
		<version>${oauth1-signer-version}</version>
	</dependency>
	<dependency>
		<groupId>com.squareup.okhttp3</groupId>
		<artifactId>okhttp</artifactId>
		<version>${okhttp-version}</version>
	</dependency>
	<dependency>
		<groupId>com.squareup.okhttp3</groupId>
		<artifactId>logging-interceptor</artifactId>
		<version>${okhttp-version}</version>
	</dependency>
	<dependency>
		<groupId>com.google.code.gson</groupId>
		<artifactId>gson</artifactId>
		<version>${gson-version}</version>
	</dependency>
	<dependency>
		<groupId>io.gsonfire</groupId>
		<artifactId>gson-fire</artifactId>
		<version>${gson-fire-version}</version>
	</dependency>
	<dependency>
		<groupId>io.swagger</groupId>
		<artifactId>swagger-annotations</artifactId>
		<version>${swagger-core-version}</version>
	</dependency>
	<dependency>
		<groupId>javax.annotation</groupId>
		<artifactId>javax.annotation-api</artifactId>
		<version>${javax-annotation-version}</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>com.google.code.findbugs</groupId>
		<artifactId>jsr305</artifactId>
		<version>3.0.2</version>
	</dependency>
	<dependency>
		<groupId>org.apache.commons</groupId>
		<artifactId>commons-lang3</artifactId>
		<version>${commons-lang3-version}</version>
	</dependency>
</dependencies>
```

### Step 6: Generate the API Client {#step-6-generate-the-api-client}

To generate the API client:

Run Maven Build by selecting **clean install** as shown in the below screen shot:

![](https://static.developer.mastercard.com/content/unified-installments/uploads/Tutorials/maven-command.png)

A new folder named **target** is created within your root directory, which contains classes generated for the schemas, and the API calls defined within the OpenAPI specification. The generated classes are available in the **target** folder as shown in the below screen shot:

![](https://static.developer.mastercard.com/content/unified-installments/uploads/Tutorials/target-folder.png)

### Step 7: Make an API Call {#step-7-make-an-api-call}

To make an API call:

* Go to the `src/main/java/` folder, and create a Java file named BnplApiReferenceApplication.java.
* Before making the API call, update the program with your OAuth credentials.

```java
String consumerKey = "your-consumer-key";
String signingKeyFilePath = "Path-to-your-p12-file";
String signingKeyAlias = "keyalias";
String signingKeyPassword = "keystorepassword";
PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword);
```

Instantiate a client with your authentication credentials, and the configuration object as interceptors before sending it.

```java
ApiClient client = new ApiClient();
client.setBasePath("https://sandbox.api.mastercard.com/installments");
client.setDebugging(true);
client.setHttpClient(client.getHttpClient()
                             .newBuilder()
                             .addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey))
                             .build());

MerchantsParticipationApi merchantsParticipationApi = new MerchantsParticipationApi(client);
MerchantParticipation merchantsParticipations = merchantsParticipationApi.getMerchantsParticipations("SPP", 0, 50);
```

The sample code block of BnplApiReferenceApplication.java after completing the above steps is as follows:

```java
import com.mastercard.developer.interceptors.OkHttpOAuth1Interceptor;
import com.mastercard.developer.utils.AuthenticationUtils;
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.MerchantsParticipationApi;
import org.openapitools.client.model.MerchantParticipation;

import java.security.PrivateKey;

public class BnplApiReferenceApplication {

    public static void main(String[] args) throws Exception {
        String consumerKey = "your-consumer-key";
        String signingKeyFilePath = "Path-to-your-p12-file";
        String signingKeyAlias = "keyalias";
        String signingKeyPassword = "keystorepassword";
        PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword);


        ApiClient client = new ApiClient();
        client.setBasePath("https://sandbox.api.mastercard.com/installments");
        client.setDebugging(true);
        client.setHttpClient(client.getHttpClient()
                                     .newBuilder()
                                     .addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey))
                                     .build());

        MerchantsParticipationApi merchantsParticipationApi = new MerchantsParticipationApi(client);
        MerchantParticipation merchantsParticipations = merchantsParticipationApi.getMerchantsParticipations("SPP", 0, 50);
    }
}
```

![](https://static.developer.mastercard.com/content/unified-installments/uploads/Tutorials/logs.png)
