C# Sample Code

This section walks through a sample C# client application. The purpose of this sample application is to show the required steps for logging in and to demonstrate the invocation and subsequent handling of several API calls.

This sample application performs the following tasks:

  1. Sets an authentication token with the returned authentication token, which is required for authentication on subsequent API calls.
  2. Creates a new Shopper object, which is a customer in the TIBCO Reward system.
  3. Sets the customer’s attribute values.
  4. Adds 50 points to the customer’s point balance.
  5. Gets and displays offers, as follows:
    1. Gets the offers for the new customer
    2. Checks to see if any of the retrieved offers are live
    3. Displays the offer if it is live
    4. Clips all of the live offers
    5. Saves the updated offer status.
  6. Gets all of the available rewards in the Rewards Catalog.
  7. Redeems the first reward in the Rewards Catalog.
  8. Gets the updated customer point balance.
///////////////////////////////////////////////////////////////////////////////////////////
//At this point we have added a web reference to https://api.loyaltylab.com/loyaltyapi/ //
//This web reference is named loyaltyapi.	//
//An API user has been created in CRMS with the email of apiuser@yourdomain.com	//
///////////////////////////////////////////////////////////////////////////////////////////
 
loyaltyapi.LoyaltyLabAPI api = new ApiTest.loyaltyapi.LoyaltyLabAPI();
api.AuthenticationResultValue = api.AuthenticateUser("apiuser@yourdomain.com", "yourpassword");
//Create a new customer object (which is named Shopper)
 
loyaltyapi.Shopper newCustomer = new loyaltyapi.Shopper();
 
//Set the user's context to be yours (alternatly you can pass in an empty guid and this
 
//will be set for you)
newCustomer.RetailerGUID = api.AuthenticationResultValue.RetailerGuid;
//Sets the new customer’s attributes newCustomer.FirstName = "Joe"; newCustomer.LastName = "User"; newCustomer.ProfileCreateDateTime = DateTime.Now; newCustomer.CreateDateTime = DateTime.Now;
newCustomer.LoyaltyLabCreateDateTime = DateTime.Now; newCustomer.EmailAddress = "apites3t@apitest2.com"; newCustomer.LoyaltyMember = true;
newCustomer.Status = "A"; newCustomer.Password = "dfds"; newCustomer.PersonStatus = "P";
 
//Creates the new customer in the TIBCO Reward system and scores the new customer for
//offers
 
newCustomer = api.CreateAndScoreShopper(newCustomer);
//Add 50 points to the customer’s point balance
 
int bal = api.AdjustShopperPoints(newCustomer.ShopperId, 50);
//Get offers for the new customer
loyaltyapi.OfferStatus[] oStatus = api.GetShopperOffers(newCustomer.ShopperId);
for(int i =0;i<offers.Length;i++){
//See if the offer is live now
if(oStatus[i].Offer.StartDateTime>DateTime.Now && oStatus[i].Offer.EndDateTime
<DateTime.Now){
//You could display offer description using oStatus[i].Offer.OfferText
 
//Clip the offers if not clipped (you generally would not
//want to clip all offers, this is just to show how you would clip one)
if(!oStatus[i].IsClipped){
oStatus[i].IsClipped = true;
//Save the status change api.UpdateShopperOfferStatus(oStatus[i]);
 
//Get all of the available rewards loyaltyapi.RewardItem[] rewards = api.GetRewards();
//Redeem the first reward – will fail if the customer does not have enough points for the
 
//reward if(rewards.Length >0){
api.RedeemReward(rewards[0].PointRedemptionCatalogId, newCustomer.ShopperId);
 
}
 
//Get the customer’s new point balance
int bal = api.GetShopperPointBalance(newCustomer.ShopperId);