Skip to main content

Usage Example

The following is a brief example that demonstrates basic SDK usage:

// First create a configuration and use it to configure the default client.

RCHAPIClientConfig *config = [[RCHAPIClientConfig alloc] initWithAPIKey:@"<api_key>"



config.APIClientSecret = @"<api_client_secret>";
config.userID = @"RZTestUser";
config.sessionID = [[NSUUID UUID] UUIDString];;
[[RCHSDK defaultClient] configure:config];

// Set the log level to debug so we can observe the API traffic

[RCHSDK setLogLevel:RCHLogLevelDebug];

// Create a "recsForPlacements" builder for the "add to cart" placement type.

RCHRequestPlacement *placement = [[RCHRequestPlacement alloc] initWithPageType:RCHPlacementPageTypeAddToCart name:@"prod1"];
RCHPlacementRecsBuilder *builder = [RCHSDK builderForRecsWithPlacement:placement];

// Execute the request, process the results, and track a view of the first product returned.

__block RCHRecommendedProduct *product;
[[RCHSDK defaultClient] sendRequest:[builder build] success:^(id responseObject) {
RCHPlacementsResult *result = responseObject;
RCHPlacement *placement = result.placements[0];
product = placement.recommendedProducts[0];

[product trackProductView];
} failure:^(id responseObject, NSError *error){
NSLog(@"Error encountered: %@", error);