diff --git a/src/pages/edge/adobe-journey-optimizer-decisioning/api-reference.md b/src/pages/edge/adobe-journey-optimizer-decisioning/api-reference.md index 95a32d7da0..8b205c785a 100644 --- a/src/pages/edge/adobe-journey-optimizer-decisioning/api-reference.md +++ b/src/pages/edge/adobe-journey-optimizer-decisioning/api-reference.md @@ -53,6 +53,22 @@ iOS +## getPropositionsWithTimeout + +This API retrieves the previously fetched propositions for the provided decision scopes from the in-memory extension propositions cache, similar to `getPropositions`. The completion callback is invoked with the decision propositions corresponding to the given decision scopes. If a certain decision scope has not been fetched prior to this API call, it will not be included in the returned propositions. + +Additionally, this API allows specifying a timeout for the operation. If the propositions retrieval does not complete within the given timeout, an error is returned, providing improved control over handling delays and ensuring timely application responses. + + + +Android + + + +iOS + + + ## onPropositionsUpdate This API registers a permanent callback which is invoked whenever the Edge extension dispatches a response event with an `eventType` of `personalization.response`. Additionally, the callback is only invoked if the response event contains at least one valid offer. The personalization response can be triggered by the `updatePropositions` API. @@ -92,6 +108,12 @@ For details on syntax, usage and availability, refer to [Mobile Core - Reset ide ## updatePropositions + + +This API has been deprecated starting in v3.2.2(Android) and v5.2.0(iOS). They will be removed in the next major release of the Optimize SDK. + +Use [`Optimize.updatePropositions`](../api-reference.md#updatepropositionswithcompletionhandler) or [`Optimize.updatePropositions`](../api-reference.md#updatepropositionswithcompletionhandlerandtimeout) APIs instead. + This API dispatches an Event for the Edge network extension to fetch decision propositions, for the provided decision scopes array, from the decisioning services enabled in the Experience Edge. The returned decision propositions are cached in-memory in the Optimize SDK extension and can be retrieved using `getPropositions` API. @@ -116,11 +138,31 @@ Completion callback passed to `updatePropositions` supports network timeout and Android - + + +iOS + + + +## updatePropositionsWithCompletionHandlerAndTimeout + +This API dispatches an event for the Edge network extension to fetch decision propositions for the provided decision scopes array from the decisioning services enabled in the Experience Edge. Similar to `updatePropositionsWithCompletionHandler`, the returned decision propositions are cached in-memory within the Optimize SDK extension and can be retrieved using the `getPropositions` API. + +Additionally, this API allows specifying a completion timeout, ensuring that the operation either completes within the given time frame or returns an error indicating a timeout. This feature provides better control over the responsiveness of the application when interacting with decisioning services. + + + +Completion callback passed to `updatePropositions` supports network timeout and fatal errors returned by edge network along with fetched propositions data. The SDK's internal retry mechanism handles the recoverable HTTP errors. As a result, recoverable HTTP errors are not returned through this callback. + + + +Android + + iOS - + ## Public classes diff --git a/src/pages/edge/adobe-journey-optimizer-decisioning/tabs/api-reference.md b/src/pages/edge/adobe-journey-optimizer-decisioning/tabs/api-reference.md index 40c1b332db..e14c6289e1 100644 --- a/src/pages/edge/adobe-journey-optimizer-decisioning/tabs/api-reference.md +++ b/src/pages/edge/adobe-journey-optimizer-decisioning/tabs/api-reference.md @@ -140,6 +140,53 @@ Optimize.getPropositions(scopes, new AdobeCallbackWithError + +#### Java + +#### Syntax + +```java +public static void getPropositions(final List decisionScopes, final double timeoutSeconds, final AdobeCallback> callback) +``` + +* _decisionScopes_ is a list of decision scopes for which propositions are requested. +* _timeoutSeconds_ is a duration in seconds specifying the maximum time `getProposition` will wait for completion before returning [AdobeError](../../home/base/mobile-core/api-reference.md#adobeerror). +* _callback_ `call` method is invoked with propositions map of type `Map`. If the callback is an instance of [AdobeCallbackWithError](../../home/base/mobile-core/api-reference.md#adobecallbackwitherror), and if the operation times out or an error occurs in retrieving propositions, the `fail` method is invoked with the appropriate [AdobeError](../../home/base/mobile-core/api-reference.md#adobeerror). + +#### Example + +```java +final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2); +final DecisionScope decisionScope2 = new DecisionScope("myScope"); + +final List decisionScopes = new ArrayList<>(); +decisionScopes.add(decisionScope1); +decisionScopes.add(decisionScope2); + +Optimize.getPropositions(scopes, 10.0, new AdobeCallbackWithError>() { + @Override + public void fail(final AdobeError adobeError) { + // handle error + } + + @Override + public void call(Map propositionsMap) { + if (propositionsMap != null && !propositionsMap.isEmpty()) { + // get the propositions for the given decision scopes + if (propositionsMap.contains(decisionScope1)) { + final OptimizeProposition proposition1 = propsMap.get(decisionScope1) + // read proposition1 offers + } + if (propositionsMap.contains(decisionScope2)) { + final OptimizeProposition proposition2 = propsMap.get(decisionScope2) + // read proposition2 offers + } + } + } +}); +``` + #### Swift @@ -158,7 +205,7 @@ static func getPropositions(for decisionScopes: [DecisionScope], ```swift let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111", - placementId: "xcore:offer-placement:1111111111111111" + placementId: "xcore:offer-placement:1111111111111111", itemCount: 2) let decisionScope2 = DecisionScope(name: "myScope") @@ -218,6 +265,90 @@ AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myS }]; ``` + + +#### Swift + +#### Syntax + +```swift +static func getPropositions(for decisionScopes: [DecisionScope], + timeout: TimeInterval, + _ completion: @escaping ([DecisionScope: OptimizeProposition]?, Error?) -> Void) +``` + +* _decisionScopes_ is an array of decision scopes for which propositions are requested. +* _timeout_ is a duration in seconds specifying the maximum time `getProposition` will wait for completion before returning `Error`. +* _completion_ is invoked with propositions dictionary of type `[DecisionScope: OptimizeProposition]`. An `Error` is returned if SDK fails to retrieve the propositions. + +#### Example + +```swift +let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111", + placementId: "xcore:offer-placement:1111111111111111", + itemCount: 2) +let decisionScope2 = DecisionScope(name: "myScope") + +Optimize.getPropositions(for: [decisionScope1, decisionScope2], timeout: 1.0) { propositionsDict, error in + + if let error = error { + // handle error + return + } + + if let propositionsDict = propositionsDict { + // get the propositions for the given decision scopes + + if let proposition1 = propositionsDict[decisionScope1] { + // read proposition1 offers + } + + if let proposition2 = propositionsDict[decisionScope2] { + // read proposition2 offers + } + } +} +``` + +#### Objective-C + +#### Syntax + +```objc ++ (void)getPropositions:(NSArray *_Nonnull) decisionScopes + timeout:(NSTimeInterval) timeout + completion:(void (^_Nonnull)(NSDictionary *_Nullable propositionsDict, NSError *_Nullable error)) completion; + +``` + +* _decisionScopes_ is an array of decision scopes for which propositions are requested. +* _timeout_ is a duration in seconds specifying the maximum time `getProposition` will wait for completion before returning `NSError`. +* _completion_ is invoked with propositions dictionary of type `NSDictionary`. An `NSError` is returned if SDK fails to retrieve the propositions. + +#### Example + +```objc +AEPDecisionScope* decisionScope1 = [[AEPDecisionScope alloc] initWithActivityId: @"xcore:offer-activity:1111111111111111" + placementId: @"xcore:offer-placement:1111111111111111" + itemCount: 2]; +AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myScope"]; + +[AEPMobileOptimize getPropositions: @[decisionScope1, decisionScope2] + timeout:1.0 + completion: ^(NSDictionary* propositionsDict, NSError* error) { + if (error != nil) { + // handle error + return; + } + + AEPOptimizeProposition* proposition1 = propositionsDict[decisionScope1]; + // read proposition1 offers + + AEPOptimizeProposition* proposition2 = propositionsDict[decisionScope2]; + // read proposition2 offers +}]; +``` + #### Java @@ -310,7 +441,7 @@ public static void updatePropositions(final List decisionScopes, ``` * _decisionScopes_ is a list of decision scopes for which propositions need updating. -* _xdm_ is a map containing additional xdm formatted data to be attached to the Experience Event. +* _xdm_ is a map containing additional XDM formatted data to be attached to the Experience Event. * _data_ is a map containing additional freeform data to be attached to the Experience Event. #### Example @@ -336,7 +467,7 @@ Optimize.updatePropositions(decisionScopes, }); ``` - + #### Java @@ -350,9 +481,9 @@ public static void updatePropositions(final List decisionScopes, ``` * _decisionScopes_ is a list of decision scopes for which propositions need updating. -* _xdm_ is a map containing additional xdm formatted data to be attached to the Experience Event. +* _xdm_ is a map containing additional XDM formatted data to be attached to the Experience Event. * _data_ is a map containing additional freeform data to be attached to the Experience Event. -* _callback_ is an optional completion handler that is invoked at the completion of the edge request. `call` method is invoked with propositions map of type `Map`. If the callback is an instance of `AdobeCallbackWithOptimizeError`, and if the operation times out or an error occurs in retrieving propositions, the `fail` method is invoked with the appropriate [AEPOptimizeError](../api-reference.md#aepoptimizeerror). _Note:_ In certain cases, both the success and failure callbacks may be triggered. To handle these cases, ensure that your implementation checks for both successful propositions and errors within the callback, as both may be present simultaneously. +* _callback_ is an optional completion handler that is invoked at the completion of the edge request. The `call` method is invoked with propositions map of type `Map`. If the callback is an instance of `AdobeCallbackWithOptimizeError`, and if the operation times out or an error occurs in retrieving propositions, the `fail` method is invoked with the appropriate [AEPOptimizeError](../api-reference.md#aepoptimizeerror). _Note:_ In certain cases, both the success and failure callbacks may be triggered. To handle these cases, ensure that your implementation checks for both successful propositions and errors within the callback, as both may be present simultaneously. #### Example @@ -388,6 +519,61 @@ Optimize.updatePropositions(decisionScopes, }); ``` + + +#### Java + +#### Syntax + +```java +public static void updatePropositions(final List decisionScopes, + final Map xdm, + final Map data, + final double timeoutSeconds, + final AdobeCallback> callback) +``` + +* _decisionScopes_ is a list of decision scopes for which propositions need updating. +* _xdm_ is a map containing additional XDM formatted data to be attached to the Experience Event. +* _data_ is a map containing additional freeform data to be attached to the Experience Event. +* _timeoutSeconds_ is a duration in seconds specifying the maximum time `updateProposition` will wait for completion before returning [AEPOptimizeError](../api-reference.md#aepoptimizeerror) which contains [AdobeError.CALLBACK_TIMEOUT](../../home/base/mobile-core/api-reference.md#adobeerror). +* _callback_ is an optional completion handler that is invoked at the completion of the edge request. The `call` method is invoked with propositions map of type `Map`. If the callback is an instance of `AdobeCallbackWithOptimizeError`, and if the operation times out or an error occurs in retrieving propositions, the `fail` method is invoked with the appropriate [AEPOptimizeError](../api-reference.md#aepoptimizeerror). _Note:_ In certain cases, both the success and failure callbacks may be triggered. To handle these cases, ensure that your implementation checks for both successful propositions and errors within the callback, as both may be present simultaneously. + +#### Example + +```java +final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2); +final DecisionScope decisionScope2 = new DecisionScope("myScope"); + +final List decisionScopes = new ArrayList<>(); +decisionScopes.add(decisionScope1); +decisionScopes.add(decisionScope2); + +Optimize.updatePropositions(decisionScopes, + new HashMap() { + { + put("xdmKey", "xdmValue"); + } + }, + new HashMap() { + { + put("dataKey", "dataValue"); + } + }, + 10.0, + new AdobeCallbackWithOptimizeError>() { + @Override + public void fail(AEPOptimizeError optimizeError) { + responseError = optimizeError; + } + + @Override + public void call(Map propositionsMap) { + responseMap = propositionsMap; + } + }); +``` + #### Swift @@ -401,14 +587,14 @@ static func updatePropositions(for decisionScopes: [DecisionScope], ``` * _decisionScopes_ is an array of decision scopes for which propositions need updating. -* _xdm_ is a dictionary containing additional xdm formatted data to be attached to the Experience Event. +* _xdm_ is a dictionary containing additional XDM formatted data to be attached to the Experience Event. * _data_ is a dictionary containing additional freeform data to be attached to the Experience Event. #### Example ```swift let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111", - placementId: "xcore:offer-placement:1111111111111111" + placementId: "xcore:offer-placement:1111111111111111", itemCount: 2) let decisionScope2 = DecisionScope(name: "myScope") @@ -428,7 +614,7 @@ Optimize.updatePropositions(for: [decisionScope1, decisionScope2] ``` * _decisionScopes_ is an array of decision scopes for which propositions need updating. -* _xdm_ is a dictionary containing additional xdm formatted data to be attached to the Experience Event. +* _xdm_ is a dictionary containing additional XDM formatted data to be attached to the Experience Event. * _data_ is a dictionary containing additional freeform data to be attached to the Experience Event. #### Example @@ -444,7 +630,7 @@ AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myS andData: @{@"dataKey": @"dataValue"}]; ``` - + #### Swift @@ -458,7 +644,7 @@ static func updatePropositions(for decisionScopes: [DecisionScope], ``` * _decisionScopes_ is an array of decision scopes for which propositions need updating. -* _xdm_ is a dictionary containing additional xdm formatted data to be attached to the Experience Event. +* _xdm_ is a dictionary containing additional XDM formatted data to be attached to the Experience Event. * _data_ is a dictionary containing additional freeform data to be attached to the Experience Event. * _completion_ is a optional completion handler invoked at the completion of the edge request with map of successful decision scopes to propositions and errors, if any. @@ -466,7 +652,7 @@ static func updatePropositions(for decisionScopes: [DecisionScope], ```swift let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111", - placementId: "xcore:offer-placement:1111111111111111" + placementId: "xcore:offer-placement:1111111111111111", itemCount: 2) let decisionScope2 = DecisionScope(name: "myScope") @@ -491,7 +677,7 @@ Optimize.updatePropositions(for: [decisionScope1, decisionScope2] ``` * _decisionScopes_ is an array of decision scopes for which propositions are requested. -* _xdm_ is a dictionary containing additional xdm formatted data to be attached to the Experience Event. +* _xdm_ is a dictionary containing additional XDM formatted data to be attached to the Experience Event. * _data_ is a dictionary containing additional freeform data to be attached to the Experience Event. * _completion_ is invoked with propositions dictionary of type `NSDictionary`. An `NSError` is returned if SDK fails to retrieve the propositions. @@ -521,6 +707,89 @@ AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myS }]; ``` + + +#### Swift + +#### Syntax + +```swift +static func updatePropositions(for decisionScopes: [DecisionScope], + withXdm xdm: [String: Any]?, + andData data: [String: Any]? = nil, + timeout: TimeInterval, + _completion: (([DecisionScope: OptimizeProposition]?, Error?) -> Void)? = nil) +``` + +* _decisionScopes_ is an array of decision scopes for which propositions need updating. +* _xdm_ is a dictionary containing additional XDM formatted data to be attached to the Experience Event. +* _data_ is a dictionary containing additional freeform data to be attached to the Experience Event. +* _timeout_ is a duration in seconds specifying the maximum time `updateProposition` will wait for completion before returning `AEPOptimizeError`. +* _completion_ is a optional completion handler invoked at the completion of the edge request with map of successful decision scopes to propositions and `AEPOptimizeError`, if any. + +#### Example + +```swift +let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111", + placementId: "xcore:offer-placement:1111111111111111", + itemCount: 2) +let decisionScope2 = DecisionScope(name: "myScope") + +Optimize.updatePropositions(for: [decisionScope1, decisionScope2], + withXdm: ["xdmKey": "xdmValue"], + andData: ["dataKey": "dataValue"], + timeout: 1.0) { data, error in + if let error = error as? AEPOptimizeError { + // handle error + } + } +``` + +#### Objective-C + +#### Syntax + +```objc ++ (void) updatePropositions: (NSArray* _Nonnull) decisionScopes + withXdm: (NSDictionary* _Nullable) xdm + andData: (NSDictionary* _Nullable) data + timeout:(NSTimeInterval) timeout + completion: (void (^ _Nonnull)(NSDictionary* _Nullable propositionsDict, NSError* _Nullable error)) completion; +``` + +* _decisionScopes_ is an array of decision scopes for which propositions are requested. +* _xdm_ is a dictionary containing additional XDM formatted data to be attached to the Experience Event. +* _data_ is a dictionary containing additional freeform data to be attached to the Experience Event. +* _timeout_ is a duration in seconds specifying the maximum time `updateProposition` will wait for completion before returning `NSError`. +* _completion_ is invoked with propositions dictionary of type `NSDictionary`. An `NSError` is returned if SDK fails to retrieve the propositions. + +#### Example + +```objc + +AEPDecisionScope* decisionScope1 = [[AEPDecisionScope alloc] initWithActivityId: @"xcore:offer-activity:1111111111111111" + placementId: @"xcore:offer-placement:1111111111111111" + itemCount: 2]; +AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myScope"]; + +[AEPMobileOptimize updatePropositions: @[decisionScope1, decisionScope2] + withXdm: @{@"xdmKey": @"xdmValue"} + andData: @{@"dataKey": @"dataValue"}] + timeout:1.0 + completion: ^(NSDictionary* propositionsDict, NSError* error) { + if (error != nil) { + // handle error + return; + } + + AEPOptimizeProposition* proposition1 = propositionsDict[decisionScope1]; + // read proposition1 offers + + AEPOptimizeProposition* proposition2 = propositionsDict[decisionScope2]; + // read proposition2 offers +}]; +``` + ##### Java