Talon.One Java SDK
[!NOTE]
The next-generation version of this SDK is available here.
The new SDK offers significant improvements, including immediate feature parity with the latest Talon.One
product releases, as well as enhanced security and reliability.
This SDK supports all of the operations of Talon.One's Integration API and Management API.
If you use Maven, we also host Maven Artifacts.
Requirements
Building the API client library requires:
- Java 21+
- Maven/Gradle
Installation
To install the API client library to your local Maven repository, execute:
mvn clean install
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
mvn clean deploy
Refer to the OSSRH Guide for more information.
Maven users
Add this dependency to your project's POM:
<dependency>
<groupId>one.talon</groupId>
<artifactId>talon-one-client</artifactId>
<version>17.0.0</version>
<scope>compile</scope>
</dependency>
Gradle users
Add this dependency to your project's build file:
compile "one.talon:talon-one-client:17.0.0"
Others
- Generate the JAR by running
mvn clean package.
- Manually install the following JARs:
target/talon-one-client-2.0.0.jar
target/lib/*.jar
Determining the base URL of the endpoints
The API is available at the same hostname as your Campaign Manager deployment.
For example, if you access the Campaign Manager at https://yourbaseurl.talon.one,
the URL for the Update customer session endpoint
is https://yourbaseurl.talon.one/v2/customer_sessions/{Id}.
Getting started
Integration API
The following code shows an example of using the Integration API:
package com.example.consumer;
import com.google.gson.Gson;
import one.talon.ApiClient;
import one.talon.api.IntegrationApi;
import one.talon.api.ManagementApi;
import one.talon.model.*;
import java.util.*;
public class TalonApiTest {
public static void main(String[] args) {
Gson gson = new Gson();
IntegrationApi iApi = new IntegrationApi(new ApiClient("api_key_v1"));
// Setup: basePath
iApi.getApiClient().setBasePath("https://yourbaseurl.talon.one"); // No trailing slash!
// Setup: when using 'api_key_v1', set apiKey & apiKeyPrefix must be provided
iApi.getApiClient().setApiKeyPrefix("ApiKey-v1");
iApi.getApiClient().setApiKey("dbc644d33aa74d582bd9479c59e16f970fe13bf34a208c39d6c7fa7586968468");
try {
// Creating a cart item object
CartItem cartItem = new CartItem();
cartItem.setName("Hawaiian Pizza");
cartItem.setSku("pizza-x");
cartItem.setQuantity(1L);
cartItem.setPrice(new java.math.BigDecimal("5.5"));
// Creating a customer session of V2
NewCustomerSessionV2 customerSession = new NewCustomerSessionV2();
customerSession.setProfileId("Cool_Dude");
customerSession.addCouponCodesItem("Cool-Summer!");
customerSession.addCartItemsItem(cartItem);
// Initiating integration request wrapping the customer session update
IntegrationRequest request = new IntegrationRequest()
.customerSession(customerSession)
// Optional parameter of requested information to be present on the response related to the customer session update
.responseContent(Arrays.asList(
IntegrationRequest.ResponseContentEnum.CUSTOMERSESSION,
IntegrationRequest.ResponseContentEnum.CUSTOMERPROFILE
));
// Flag to communicate whether the request is a "dry run"
Boolean dryRun = false;
// Create/update a customer session using `updateCustomerSessionV2` function
IntegrationStateV2 is = iApi.updateCustomerSessionV2("deetdoot", request, dryRun, null);
System.out.println(is.toString());
// Parsing the returned effects list, please consult https://developers.talon.one/Integration-API/handling-effects-v2 for the full list of effects and their corresponding properties
for (Effect eff : is.getEffects()) {
if (eff.getEffectType().equals("addLoyaltyPoints")) {
// Typecasting according to the specific effect type
AddLoyaltyPointsEffectProps props = gson.fromJson(
gson.toJson(eff.getProps()),
AddLoyaltyPointsEffectProps.class
);
// Access the specific effect's properties
System.out.println(props.getName());
System.out.println(props.getProgramId());
System.out.println(props.getValue());
}
if (eff.getEffectType().equals("acceptCoupon")) {
// Typecasting according to the specific effect type
AcceptCouponEffectProps props = gson.fromJson(
gson.toJson(eff.getProps()),
AcceptCouponEffectProps.class
);
// work with AcceptCouponEffectProps' properties
// ...
}
}
} catch (Exception e) {
System.out.println(e);
}
}
}
Management API
The following code shows an example of using the Management API:
package com.example.consumer;
import one.talon.ApiClient;
import one.talon.api.IntegrationApi;
import one.talon.api.ManagementApi;
import one.talon.model.*;
public class TalonApiTest {
public static void main(String[] args) {
// Management API example to load application with id 7
ManagementApi mApi = new ManagementApi(new ApiClient("management_key"));
// Setup: basePath
mApi.getApiClient().setBasePath("https://yourbaseurl.talon.one"); // No trailing slash!
// Setup: when using 'management_key', set apiKey & apiKeyPrefix must be provided
mApi.getApiClient().setApiKeyPrefix("ManagementKey-v1");
mApi.getApiClient().setApiKey("2f0dce055da01ae595005d7d79154bae7448d319d5fc7c5b2951fadd6ba1ea07");
try {
// Calling `getApplication` function with the desired id (7)
Application application = mApi.getApplication(7L);
System.out.println(application.toString());
} catch (Exception e) {
System.out.println(e);
}
}
}
Documentation for API endpoints
All URLs are relative to https://yourbaseurl.talon.one.
| Class |
Method |
HTTP request |
Description |
| IntegrationApi |
activateLoyaltyPoints |
POST /v1/loyalty_programs/{loyaltyProgramId}/activate_points |
Activate loyalty points |
| IntegrationApi |
bestPriorPrice |
POST /v1/best_prior_price |
Fetch best prior price |
| IntegrationApi |
createAudienceV2 |
POST /v2/audiences |
Create audience |
| IntegrationApi |
createCouponReservation |
POST /v1/coupon_reservations/{couponValue} |
Create coupon reservation |
| IntegrationApi |
createReferral |
POST /v1/referrals |
Create referral code for an advocate |
| IntegrationApi |
createReferralsForMultipleAdvocates |
POST /v1/referrals_for_multiple_advocates |
Create referral codes for multiple advocates |
| IntegrationApi |
deleteAudienceMembershipsV2 |
DELETE /v2/audiences/{audienceId}/memberships |
Delete audience memberships |
| IntegrationApi |
deleteAudienceV2 |
DELETE /v2/audiences/{audienceId} |
Delete audience |
| IntegrationApi |
deleteCouponReservation |
DELETE /v1/coupon_reservations/{couponValue} |
Delete coupon reservations |
| IntegrationApi |
deleteCustomerData |
DELETE /v1/customer_data/{integrationId} |
Delete customer's personal data |
| IntegrationApi |
deleteLoyaltyTransactionsFromLedgers |
POST /v1/loyalty_programs/{loyaltyProgramId}/profile/{integrationId}/delete_transactions |
Delete customer's transactions from loyalty ledgers |
| IntegrationApi |
generateLoyaltyCard |
POST /v1/loyalty_programs/{loyaltyProgramId}/cards |
Generate loyalty card |
| IntegrationApi |
getCustomerAchievementHistory |
GET /v1/customer_profiles/{integrationId}/achievements/{achievementId} |
List customer's achievement history |
| IntegrationApi |
getCustomerAchievements |
GET /v1/customer_profiles/{integrationId}/achievements |
List customer's available achievements |
| IntegrationApi |
getCustomerInventory |
GET /v1/customer_profiles/{integrationId}/inventory |
List customer data |
| IntegrationApi |
getCustomerRewards |
GET /v1/customer_profiles/{integrationId}/rewards |
List customer's rewards |
| IntegrationApi |
getCustomerSession |
GET /v2/customer_sessions/{customerSessionId} |
Get customer session |
| IntegrationApi |
getEventV3 |
GET /v3/events/{integrationId} |
Get advanced event |
| IntegrationApi |
getLoyaltyBalances |
GET /v1/loyalty_programs/{loyaltyProgramId}/profile/{integrationId}/balances |
Get customer's loyalty balances |
| IntegrationApi |
getLoyaltyCardBalances |
GET /v1/loyalty_programs/{loyaltyProgramId}/cards/{loyaltyCardId}/balances |
Get card's point balances |
| IntegrationApi |
getLoyaltyCardPoints |
GET /v1/loyalty_programs/{loyaltyProgramId}/cards/{loyaltyCardId}/points |
List card's unused loyalty points |
| IntegrationApi |
getLoyaltyCardTransactions |
GET /v1/loyalty_programs/{loyaltyProgramId}/cards/{loyaltyCardId}/transactions |
List card's transactions |