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 42dbcdbf0f..1627360884 100644 --- a/src/pages/edge/adobe-journey-optimizer-decisioning/api-reference.md +++ b/src/pages/edge/adobe-journey-optimizer-decisioning/api-reference.md @@ -104,13 +104,32 @@ iOS +## updatePropositionsWithCompletionHandler + +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. + + + +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 + +Coming Soon + +iOS + + + ## Public classes -| Type | Android | (AEP 5.x) Swift | (AEP 5.x) Objective-C | -| :--- | :--- | :--- | :--- | +| Type | Android | (AEP 5.x) Swift | (AEP 5.x) Objective-C | +| :--- |:----------------| :--- | :--- | | class | `DecisionScope` | `DecisionScope` | `AEPDecisionScope` | -| class | `Proposition` | `OptimizeProposition` | `AEPOptimizeProposition` | -| class | `Offer` | `Offer` | `AEPOffer` | +| class | `Proposition` | `OptimizeProposition` | `AEPOptimizeProposition` | +| class | `Offer` | `Offer` | `AEPOffer` | +| class | Coming Soon | `AEPOptimizeError` | `AEPOptimizeError` | ### DecisionScope @@ -171,3 +190,17 @@ Android iOS + +### AEPOptimizeError + +This class represents the error details returned by the Edge Network while fetching propositions. + + + +Android + +**Coming Soon** + +iOS + + 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 ae1b06b186..ecf206e4cd 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 @@ -336,6 +336,58 @@ Optimize.updatePropositions(decisionScopes, }); ``` + + +#### Java + +#### Syntax + +```java +public static void updatePropositions(final List decisionScopes, + final Map xdm, + final Map data, + 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. +* _callback_ 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. + +#### 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"); + } + }, + new AdobeCallbackWithOptimizeError>() { + @Override + public void fail(AEPOptimizeError optimizeError) { + responseError = optimizeError; + } + + @Override + public void call(Map propositionsMap) { + responseMap = propositionsMap; + } + }); +``` + #### Swift @@ -392,6 +444,83 @@ AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myS andData: @{@"dataKey": @"dataValue"}]; ``` + + +#### Swift + +#### Syntax + +```swift +static func updatePropositions(for decisionScopes: [DecisionScope], + withXdm xdm: [String: Any]?, + andData data: [String: Any]? = nil, + _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. +* _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. + +#### 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"]) { 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 + 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. +* _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"}] + 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 @@ -777,7 +906,7 @@ public class Offer: NSObject, Codable { @objc public let etag: String /// Offer priority score - @objc public let score: Int + @objc public let score: Double /// Offer schema string @objc public let schema: String @@ -880,3 +1009,58 @@ public enum OfferType: Int, Codable { init(from format: String) {...} } ``` + + + +#### Swift + +Error details received from Edge response along with [AEPError](../../../home/base/mobile-core/tabs/api-reference/#aeperror) object returned with values: + +* _AEPError.callbackTimeout_ is returned when request timeout without any response. +* _AEPError.serverErrors_ is returned for HTTP Status 500. +* _AEPError.invalidRequest_ is returned for HTTP Status 400 - 499 (except 408 and 429). + +```swift +@objc(AEPOptimizeError) +public class AEPOptimizeError: NSObject, Error { + // This is a URI reference (RFC3986) that identifies the problem type + public let type: String? + + // This is the HTTP status code generated by the server for this occurrence of the problem. + public let status: Int? + + // This is a short, human-readable summary of the problem type. + public let title: String? + + // This is human-readable description of the problem type. + public let detail: String? + + // This is a map of additional properties that aid in debugging such as the request ID or the org ID. In some cases, it might contain data specific to the error at hand, such as a list of validation errors. + public let report: [String: Any]? + + // This ia a mandatory AEPError representing the high level error status + public var aepError = AEPError.unexpected + + // Initializer for AEPOptimizeError based based on the Error details returned by Edge respose + public init(type: String?, status: Int?, title: String?, detail: String?, aepError: AEPError? = nil) {...} +} +``` + + + +#### Kotlin + +Error details received from Edge response along with [AdobeError](../../../home/base/mobile-core/tabs/api-reference/#adobeerror) object returned with values: + +* _AdobeError.CALLBACK_TIMEOUT_ is returned when request timeout without any response. +* _AdobeError.SERVER_ERROR_ is returned for HTTP Status 500. +* _AdobeError.INVALID_REQUEST_ is returned for HTTP Status 400 - 499 (except 408 and 429). + +```kotlin +class AEPOptimizeError(val type: String? = "", + val status: Int? = 0, + val title: String? = "", + val detail: String? = "", + var report: Map?, + var adobeError: AdobeError?) {...} +``` diff --git a/src/pages/home/base/mobile-core/tabs/api-reference.md b/src/pages/home/base/mobile-core/tabs/api-reference.md index 6ec14c5d9b..0a42528e47 100644 --- a/src/pages/home/base/mobile-core/tabs/api-reference.md +++ b/src/pages/home/base/mobile-core/tabs/api-reference.md @@ -1414,6 +1414,10 @@ The `AdobeError` class shows the errors that can be passed to an `AdobeCallbackW * `CALLBACK_TIMEOUT` - The timeout was met. * `CALLBACK_NULL` - The provided callback function is null. * `EXTENSION_NOT_INITIALIZED` - The extension is not initialized. +* `SERVER_ERROR` - There was a server error. +* `NETWORK_ERROR` - There was a network error. +* `INVALID_REQUEST` - There was an invalid request. +* `INVALID_RESPONSE` - There was an invalid response. **Example** @@ -1429,6 +1433,14 @@ MobileCore.getPrivacyStatus(new AdobeCallbackWithError() { // handle null callback error } else if (error == AdobeError.EXTENSION_NOT_INITIALIZED) { // handle extension not initialized error + } else if (error == AdobeError.SERVER_ERROR) { + // handle server error + } else if (error == AdobeError.NETWORK_ERROR) { + // handle network error + } else if (error == AdobeError.INVALID_REQUEST) { + // handle invalid request error + } else if (error == AdobeError.INVALID_RESPONSE) { + // handle invalid response error } }