# Making an API Call source: https://developer.mastercard.com/doconomy-aland-index/tutorial/build-end-to-end-application/step3/index.md ## Making an API Call {#making-an-api-call} * Under src/main/java/, create a Java file named **CarbonImpactApiMain.java**. * To make the API call, you need to make your OAuth credentials available to the program to use. * Java ```java String consumerKey = ""; String signingKeyFilePath = ""; String signingKeyAlias = ""; String signingKeyPassword = ""; PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword); ``` * Now you need to instantiate a client with your authentication credentials before you can send it. * Java ```java ApiClient client = new ApiClient(); client.setBasePath("https://sandbox.api.mastercard.com/doconomy"); client.setDebugging(true); client.setReadTimeout(40000); OkHttpClient.Builder httpClientBuilder = client.getHttpClient().newBuilder(); httpClientBuilder.addInterceptor(new ForceJsonResponseInterceptor()); httpClientBuilder.addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey)); client.setHttpClient(httpClientBuilder.build()); EnvironmentalImpactApi environmentalImpactApi = new EnvironmentalImpactApi(client); SupportedParametersApi supportedParametersApi = new SupportedParametersApi(client); ``` * The interceptor that you use to sign a request is also provided by the Mastercard OAuth library. * Java ```java 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(); } } ``` * The following code demonstrates how we invoke our APIs in collaboration with our client.Content of CarbonImpactApiMain.java. * 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); OkHttpClient.Builder httpClientBuilder = client.getHttpClient().newBuilder(); httpClientBuilder.addInterceptor(new ForceJsonResponseInterceptor()); httpClientBuilder.addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey)); client.setHttpClient(httpClientBuilder.build()); EnvironmentalImpactApi environmentalImpactApi = new EnvironmentalImpactApi(client); SupportedParametersApi supportedParametersApi = new SupportedParametersApi(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 = environmentalImpactApi.footprintsByTransactionData(mcTransactions); System.out.println("Calculate Transaction Footprint response : " + transactionFootprints); System.out.println("Calling Get Supported Currencies"); MCSupportedCurrencies currencies = supportedParametersApi.getSupportedCurrencies(); System.out.println("Get Supported Currencies response : " + currencies); System.out.println("Calling Get Supported Merchant Categories"); MCSupportedMerchantCategories mcSupportedMerchantCategories = supportedParametersApi.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(); } } } ```