# 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 org.openapitools openapi-generator-maven-plugin 5.4.0 BNPL REST API Client generate ${project.basedir}/src/main/resources/merchant-participation-api-swagger.yml java false false src/gen/java/main true java8 Date=LocalDate ``` 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 org.springframework.boot spring-boot-starter-parent 2.7.1 11 1.5.2 4.9.1 2.9.0 1.8.5 1.6.6 1.3.2 3.11 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test com.mastercard.developer oauth1-signer ${oauth1-signer-version} com.squareup.okhttp3 okhttp ${okhttp-version} com.squareup.okhttp3 logging-interceptor ${okhttp-version} com.google.code.gson gson ${gson-version} io.gsonfire gson-fire ${gson-fire-version} io.swagger swagger-annotations ${swagger-core-version} javax.annotation javax.annotation-api ${javax-annotation-version} provided com.google.code.findbugs jsr305 3.0.2 org.apache.commons commons-lang3 ${commons-lang3-version} ``` ### 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)