# Making an API Call source: https://developer.mastercard.com/doconomy-aland-index/tutorial/create-your-own-reference-app/step3/index.md ## Step 3: Making an API Call {#step-3-making-an-api-call} Create a Java file, called **CarbonImpactApiMain.java**, at src/main/java/. To make the API call, you need to make your OAuth credentials available to the program to use. * Oauth ```Oauth String consumerKey = "your consumer key"; String signingKeyFilePath = "/path/to/your/key.p12"; String signingKeyAlias = "your key alias"; String signingKeyPassword = "your password"; PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword); ``` Afterwards, you instantiate a client that you can set up to sign requests that you send with your authentication credentials. * Client-Instantiation ```Client-Instantiation ApiClient client = new ApiClient(); client.setBasePath("https://sandbox.api.mastercard.com"); client.setDebugging(true); client.setReadTimeout(40000); List interceptors = client.getHttpClient().networkInterceptors(); interceptors.add(new ForceJsonResponseInterceptor()); interceptors.add(new OkHttp2OAuth1Interceptor(consumerKey, signingKey)); CarbonImpactApi carbonImpactApi = new CarbonImpactApi(client); ``` The interceptor that you use to sign requests is also provided by the Mastercard OAuth library. * Interceptor ```Interceptor private static class ForceJsonResponseInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); String withJsonFormatUrl = withJsonFormat(originalRequest.uri().toString()); Request newRequest = originalRequest.newBuilder().url(withJsonFormatUrl).build(); return chain.proceed(newRequest); } private String withJsonFormat(String uri) { StringBuilder newUri = new StringBuilder(uri); newUri.append(uri.contains("?") ? "&" : "?"); newUri.append("Format=JSON"); return newUri.toString(); } } ``` ## Content of CarbonImpactApiMain.java {#content-of-carbonimpactapimainjava} * Java ```java package com.mastercard.developer.doconomyalandindex; import com.mastercard.developer.interceptors.OkHttp2OAuth1Interceptor; import com.mastercard.developer.utils.AuthenticationUtils; import com.squareup.okhttp.Interceptor; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import org.openapitools.client.ApiClient; import org.openapitools.client.api.CarbonImpactApi; import org.openapitools.client.model.*; import java.io.IOException; import java.math.BigDecimal; import java.security.PrivateKey; import java.util.List; public class CarbonImpactApiMain { public static void main(String[] args) throws Exception { ApiClient client = new ApiClient(); String consumerKey = "your consumer key"; String signingKeyFilePath = "/path/to/your/key.p12"; String signingKeyAlias = "your key alias"; String signingKeyPassword = "your password"; PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword); client.setBasePath("https://sandbox.api.mastercard.com/doconomy"); client.setDebugging(true); client.setReadTimeout(40000); List interceptors = client.getHttpClient().networkInterceptors(); interceptors.add(new ForceJsonResponseInterceptor()); interceptors.add(new OkHttp2OAuth1Interceptor(consumerKey, signingKey)); CarbonImpactApi carbonImpactApi = new CarbonImpactApi(client); System.out.println("Calling Calculate Transaction Footprint"); MCTransactions mcTransactions = new MCTransactions() .addTransactionsItem(new MCTransaction().transactionId("TX-1") .mcc("3000").amount( new MCAmount().currencyCode("EUR").value(new BigDecimal(150)))); MCTransactionFootprints transactionFootprints = carbonImpactApi.footprintsByTransactionData(mcTransactions); System.out.println("Calculate Transaction Footprint response : " + transactionFootprints); System.out.println("Calling Get Supported Currencies"); MCSupportedCurrencies currencies = carbonImpactApi.getSupportedCurrencies(); System.out.println("Get Supported Currencies response : " + currencies); System.out.println("Calling Get Supported Merchant Categories"); MCSupportedMerchantCategories mcSupportedMerchantCategories = carbonImpactApi.getSupportedMerchantCategories(); System.out.println("Get Supported Merchant Categories response : " + mcSupportedMerchantCategories); } /** * Add "Format=JSON" to the request for the service/gateway to return a JSON response. */ private static class ForceJsonResponseInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); String withJsonFormatUrl = withJsonFormat(originalRequest.uri().toString()); Request newRequest = originalRequest.newBuilder().url(withJsonFormatUrl).build(); return chain.proceed(newRequest); } private String withJsonFormat(String uri) { StringBuilder newUri = new StringBuilder(uri); newUri.append(uri.contains("?") ? "&" : "?"); newUri.append("Format=JSON"); return newUri.toString(); } } } ```