This project showcases the use case of retrieving sbde metrics using the SBDE API v2. This application illustrates connecting to the SBDE API using Mastercard's OAuth library. You will need a consumer key, .p12 files, and your keystore alias and password. This application is the output of a tutorial from sbde V2.
- Java 8 or later
A tutorial can be found here for setting up and using this service.
- Mastercard Developers Account
- A text editor or IDE
- Java 8+
- Apache Maven 3.3+
- Set up the
JAVA_HOME
environment variable to match the location of your Java installation.
- Create an account at Mastercard Developers.
- Create a new project and add the
SBDE
API to your project.- A zip file will be downloaded automatically with your keys.
- Take note of the given consumer key, keyalias, and keystore password given upon the project creation.
- Copy the downloaded
.p12
file to/src/main/resources
. - Update the properties found in
src/main/java/com/mastercard/sbde/ApiService.java
.
private static final String API_BASE_PATH = "https://sandbox.api.mastercard.com/sbde/metrics-api";
//Below properties will be required for authentication of API calls.
private static final String CONSUMER_KEY = "Your consumer key"; // This refers to your consumer key. Copy it from "Keys" section on your project page in [Mastercard Developers](https://developer.mastercard.com/dashboard)
private static final String SIGNING_KEY_ALIAS = "your key alias"; // This is the default value of key alias. If it is modified, use the updated one from keys section in [Mastercard Developers](https://developer.mastercard.com/dashboard).
private static final String SIGNING_KEY_FILE_PATH = "path to your.p12 private key file"; // This refers to .p12 file found in the signing key. Please place .p12 file at src\main\resources in the project folder and add classpath for .p12 file.
private static final String SIGNING_KEY_PASSWORD = "your password"; // This is the default value of key alias. If it is modified, use the updated one from keys section in [Mastercard Developers](https://developer.mastercard.com/dashboard).
- Run
mvn clean compile
from the root of the project directory.- When compile is run, the OpenAPI Generator plugin will generate the sources for connecting to the SBDE API.
- run
mvn exec:java -Dexec.mainClass="com.mastercard.sbde.Main"
to run the project.
- Select an endpoint from the dropdown menu at the top of the application
- Fill in the required parameters and click submit
- Click on 'JSON Response' to view the raw JSON returned by the API call
OpenAPI Generator generates API client libraries from OpenAPI Specs. It provides generators and library templates for supporting multiple languages and frameworks.
See also:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.3.4</version>
<executions>
<execution>
<id> Small Business Decision Enhancer 2.0 REST Client</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/small-business-decision-enhancer.yaml</inputSpec>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<dateLibrary>java8</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
These are the parameters used for the SBDE API. All parameters are optional.
Name | Type | Default Value | Purpose |
---|---|---|---|
from_date | string | null | Date in formation yyyy-MM-dd. Used as the most recent date to search for. |
to_date | string | null | Date in formation yyyy-MM-dd. Used as the oldest date to search for. |
offset | int | 0 | For Pagination; offset is used to offset the start of the list. |
limit | int | 25 | For Pagination; limit is used to limit the number of entities returned |
sort | string | +period | Sorts the results + for ascending, - for descending and any property from the result. |
Get information on a specific merchant location.
URL | Method | Parameters | Request Model | Response model |
---|---|---|---|---|
/merchant-locations/{merchant_location_id} | GET | - | int | MerchantLocation |
Get a paginated list of all merchant location daily metrics.
URL | Method | Parameters | Request Model | Response model |
---|---|---|---|---|
/merchant-locations/{merchant_location_id}/metrics/daily-metrics | GET | from_date, to_date, offset, limit, sort | int | MerchantLocationDailyMetrics |
Get a list of all merchant location performance metrics.
URL | Method | Parameters | Request Model | Response model |
---|---|---|---|---|
/merchant-locations/{merchant_location_id}/metrics/merchant-performance-metrics | GET | from_date, to_date, sort | int | MerchantLocationPerformanceMetrics |
See the API Reference page in the documentation.
This dependency is required to properly call the API.
<dependency>
<groupId>com.mastercard.developer</groupId>
<artifactId>oauth1-signer</artifactId>
<version>1.2.3</version>
</dependency>
Link to the oauth1 library's Github
See the code used in this application to utilize the library.
Found in /src/java/ com.mastercard.sbde.ApiService
ApiClient client = new ApiClient();
client.setBasePath(API_BASE_PATH); //If you use any other sandbox url then please add sbde/metrics-api as an extension
client.setDebugging(true);
List<Interceptor> interceptors = client.getHttpClient().networkInterceptors();
interceptors.add(new Main.ForceJsonResponseInterceptor());
interceptors.add(new OkHttp2OAuth1Interceptor(CONSUMER_KEY, signingKey));
merchantLocationApi = new MerchantLocationApi(client);
merchantLocationMetricsApi = new MerchantLocationMetricsApi(client);
merchantLocationPerformanceMetricsApi = new MerchantLocationPerformanceMetricsApi(client);
If you would like further information, please send an email to apisupport@mastercard.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 1994-2020, All Rights Reserved by Mastercard.