Code-based Experiences & Content Cards - API reference
This document lists the public APIs available in the Messaging extension for implementing code-based experiences and content cards.
getPropositionsForSurfaces
The getPropositionsForSurfaces API retrieves the previously fetched propositions from the SDK's in-memory propositions cache for the provided surfaces. The completion handler is invoked with the decision propositions corresponding to the given surfaces or AEPError, if it occurs.
If a requested surface was not previously cached prior to calling getPropositionsForSurfaces (using the updatePropositionsForSurfaces API), no propositions will be returned for that surface.
Java
Syntax
Copied to your clipboardpublic static void getPropositionsForSurfaces(@NonNull final List<Surface> surfaces, @NonNull final AdobeCallback<Map<Surface, List<Proposition>>> callback)
- surfaces is a list of surfaces for which propositions are requested.
- callback
callmethod is invoked with propositions map of typeMap<Surface, List<Proposition>>. If the callback is an instance of AdobeCallbackWithError, and if the operation times out or an error occurs in retrieving propositions, thefailmethod is invoked with the appropriate AdobeError.
Example
Kotlin
Copied to your clipboardval surface1 = Surface("myActivity#button")val surface2 = Surface("myActivityAttributes")val surfaces = listOf(surface1, surface2)Messaging.getPropositionsForSurfaces(surfaces) {it?.let { propositionsMap ->if (propositionsMap.isNotEmpty()) {// get the propositions for the given surfacespropositionsMap[surface1]?.let {// read surface1 propositions}propositionsMap[surface2]?.let {// read surface2 propositions}}}}
Java
Copied to your clipboardfinal Surface surface1 = new Surface("myActivity#button");final Surface surface2 = new Surface("myActivityAttributes");final List<Surface> surfaces = new ArrayList<>();surfaces.add(surface1);surfaces.add(surface2);Messaging.getPropositionsForSurfaces(surfaces, new AdobeCallbackWithError<Map<Surface, List<Proposition>>>() {@Overridepublic void fail(final AdobeError adobeError) {// handle error}@Overridepublic void call(Map<Surface, List<Proposition>> propositionsMap) {if (propositionsMap != null && !propositionsMap.isEmpty()) {// get the propositions for the given surfacesif (propositionsMap.contains(surface1)) {final List<Proposition> propositions1 = propositionsMap.get(surface1)// read surface1 propositions}if (propositionsMap.contains(surface2)) {final List<Proposition> proposition2 = propositionsMap.get(surface2)// read surface2 propositions}}}});
Swift
Syntax
Copied to your clipboardstatic func getPropositionsForSurfaces(_ surfacePaths: [Surface], _ completion: @escaping ([Surface: [Proposition]]?, Error?) -> Void)
- surfaces is an array of surfaces for which propositions are requested.
- completion is invoked with propositions dictionary of type
[Surface: [Proposition]]. AnErroris returned if SDK fails to retrieve the propositions.
Example
Copied to your clipboardlet surface1 = Surface(path: "myView#button")let surface2 = Surface(path: "myViewAttributes")Messaging.getPropositionsForSurfaces([surface1, surface2]) { propositionsDict, error inguard error == nil else {// handle errorreturn}guard let propositionsDict = propositionsDict else {// bail early if no propositionsreturn}// get the propositions for the given surfacesif let propositions1 = propositionsDict[surface1] {// read surface1 propositions}if let propositions2 = propositionsDict[surface2] {// read surface2 propositions}}
Objective-C
Syntax
Copied to your clipboard+ (void) getPropositionsForSurfaces: (NSArray<AEPSurface*>* _Nonnull) surfacescompletion: (void (^ _Nonnull)(NSDictionary<AEPSurface*, NSArray<AEPProposition*>*>* _Nullable propositionsDict, NSError* _Nullable error)) completion;
- surfaces is an array of surfaces for which propositions are requested.
- completion is invoked with propositions dictionary of type
NSDictionary<AEPSurface*, NSArray<AEPProposition*>*>. AnNSErroris returned if SDK fails to retrieve the propositions.
Example
Copied to your clipboardAEPSurface* surface1 = [[AEPSurface alloc] initWithPath: @"myView#button"];AEPSurface* surface2 = [[AEPSurface alloc] initWithPath: @"myView#button"];[AEPMobileMessaging getPropositionsForSurfaces: @[surface1, surface2]completion: ^(NSDictionary<AEPDecisionScope*, NSArray<AEPProposition*>*>* propositionsDict, NSError* error) {if (error != nil) {// handle errorreturn;}NSArray<AEPProposition*>* proposition1 = propositionsDict[surface1];// read surface1 propositionsNSArray<AEPProposition*>* proposition2 = propositionsDict[surface2];// read surface2 propositions}];
Java
Syntax
Copied to your clipboardpublic static void getPropositionsForSurfaces(@NonNull final List<Surface> surfaces, @NonNull final AdobeCallback<Map<Surface, List<Proposition>>> callback)
- surfaces is a list of surfaces for which propositions are requested.
- callback
callmethod is invoked with propositions map of typeMap<Surface, List<Proposition>>. If the callback is an instance of AdobeCallbackWithError, and if the operation times out or an error occurs in retrieving propositions, thefailmethod is invoked with the appropriate AdobeError.
Example
Kotlin
Copied to your clipboardval surface1 = Surface("myActivity#button")val surface2 = Surface("myActivityAttributes")val surfaces = listOf(surface1, surface2)Messaging.getPropositionsForSurfaces(surfaces) {it?.let { propositionsMap ->if (propositionsMap.isNotEmpty()) {// get the propositions for the given surfacespropositionsMap[surface1]?.let {// read surface1 propositions}propositionsMap[surface2]?.let {// read surface2 propositions}}}}
Java
Copied to your clipboardfinal Surface surface1 = new Surface("myActivity#button");final Surface surface2 = new Surface("myActivityAttributes");final List<Surface> surfaces = new ArrayList<>();surfaces.add(surface1);surfaces.add(surface2);Messaging.getPropositionsForSurfaces(surfaces, new AdobeCallbackWithError<Map<Surface, List<Proposition>>>() {@Overridepublic void fail(final AdobeError adobeError) {// handle error}@Overridepublic void call(Map<Surface, List<Proposition>> propositionsMap) {if (propositionsMap != null && !propositionsMap.isEmpty()) {// get the propositions for the given surfacesif (propositionsMap.contains(surface1)) {final List<Proposition> propositions1 = propositionsMap.get(surface1)// read surface1 propositions}if (propositionsMap.contains(surface2)) {final List<Proposition> proposition2 = propositionsMap.get(surface2)// read surface2 propositions}}}});
Swift
Syntax
Copied to your clipboardstatic func getPropositionsForSurfaces(_ surfacePaths: [Surface], _ completion: @escaping ([Surface: [Proposition]]?, Error?) -> Void)
- surfaces is an array of surfaces for which propositions are requested.
- completion is invoked with propositions dictionary of type
[Surface: [Proposition]]. AnErroris returned if SDK fails to retrieve the propositions.
Example
Copied to your clipboardlet surface1 = Surface(path: "myView#button")let surface2 = Surface(path: "myViewAttributes")Messaging.getPropositionsForSurfaces([surface1, surface2]) { propositionsDict, error inguard error == nil else {// handle errorreturn}guard let propositionsDict = propositionsDict else {// bail early if no propositionsreturn}// get the propositions for the given surfacesif let propositions1 = propositionsDict[surface1] {// read surface1 propositions}if let propositions2 = propositionsDict[surface2] {// read surface2 propositions}}
Objective-C
Syntax
Copied to your clipboard+ (void) getPropositionsForSurfaces: (NSArray<AEPSurface*>* _Nonnull) surfacescompletion: (void (^ _Nonnull)(NSDictionary<AEPSurface*, NSArray<AEPProposition*>*>* _Nullable propositionsDict, NSError* _Nullable error)) completion;
- surfaces is an array of surfaces for which propositions are requested.
- completion is invoked with propositions dictionary of type
NSDictionary<AEPSurface*, NSArray<AEPProposition*>*>. AnNSErroris returned if SDK fails to retrieve the propositions.
Example
Copied to your clipboardAEPSurface* surface1 = [[AEPSurface alloc] initWithPath: @"myView#button"];AEPSurface* surface2 = [[AEPSurface alloc] initWithPath: @"myView#button"];[AEPMobileMessaging getPropositionsForSurfaces: @[surface1, surface2]completion: ^(NSDictionary<AEPDecisionScope*, NSArray<AEPProposition*>*>* propositionsDict, NSError* error) {if (error != nil) {// handle errorreturn;}NSArray<AEPProposition*>* proposition1 = propositionsDict[surface1];// read surface1 propositionsNSArray<AEPProposition*>* proposition2 = propositionsDict[surface2];// read surface2 propositions}];
updatePropositionsForSurfaces
The updatePropositionsForSurfaces API dispatches an event for the Edge network extension to fetch personalization decisions from the AJO campaigns for the provided surfaces array. The returned decision propositions are cached in-memory by the Messaging extension.
To retrieve previously cached decision propositions, use getPropositionsForSurfaces API.
Java
Syntax
Copied to your clipboardpublic static void updatePropositionsForSurfaces(@NonNull final List<Surface> surfaces)
- surfaces is a list of surfaces for which propositions need updating.
Example
Kotlin
Copied to your clipboardval surface1 = Surface("myActivity#button")val surface2 = Surface("myActivityAttributes")val surfaces = listOf(surface1, surface2)Messaging.updatePropositionsForSurfaces(surfaces)
Java
Copied to your clipboardfinal Surface surface1 = new Surface("myActivity#button");final Surface surface2 = new Surface("myActivityAttributes");final List<Surface> surfaces = new ArrayList<>();surfaces.add(surface1);surfaces.add(surface2);Messaging.updatePropositionsForSurfaces(surfaces)
Swift
Syntax
Copied to your clipboardstatic func updatePropositionsForSurfaces(_ surfaces: [Surface])
- surfaces is an array of surfaces for which propositions need updating.
Example
Copied to your clipboardlet surface1 = Surface(path: "myView#button")let surface2 = Surface(path: "myViewAttributes")Messaging.updatePropositionsForSurfaces([surface1, surface2])
Objective-C
Syntax
Copied to your clipboard+ (void) updatePropositionsForSurfaces: (NSArray<AEPSurface*>* _Nonnull) surfaces;
- surfaces is an array of surfaces for which propositions need updating.
Example
Copied to your clipboardAEPSurface* surface1 = [[AEPSurface alloc] initWithPath: @"myView#button"];AEPSurface* surface2 = [[AEPSurface alloc] initWithPath: @"myView#button"];[AEPMobileMessaging updatePropositionsForSurfaces: @[surface1, surface2]];
Java
Syntax
Copied to your clipboardpublic static void updatePropositionsForSurfaces(@NonNull final List<Surface> surfaces)
- surfaces is a list of surfaces for which propositions need updating.
Example
Kotlin
Copied to your clipboardval surface1 = Surface("myActivity#button")val surface2 = Surface("myActivityAttributes")val surfaces = listOf(surface1, surface2)Messaging.updatePropositionsForSurfaces(surfaces)
Java
Copied to your clipboardfinal Surface surface1 = new Surface("myActivity#button");final Surface surface2 = new Surface("myActivityAttributes");final List<Surface> surfaces = new ArrayList<>();surfaces.add(surface1);surfaces.add(surface2);Messaging.updatePropositionsForSurfaces(surfaces)
Swift
Syntax
Copied to your clipboardstatic func updatePropositionsForSurfaces(_ surfaces: [Surface])
- surfaces is an array of surfaces for which propositions need updating.
Example
Copied to your clipboardlet surface1 = Surface(path: "myView#button")let surface2 = Surface(path: "myViewAttributes")Messaging.updatePropositionsForSurfaces([surface1, surface2])
Objective-C
Syntax
Copied to your clipboard+ (void) updatePropositionsForSurfaces: (NSArray<AEPSurface*>* _Nonnull) surfaces;
- surfaces is an array of surfaces for which propositions need updating.
Example
Copied to your clipboardAEPSurface* surface1 = [[AEPSurface alloc] initWithPath: @"myView#button"];AEPSurface* surface2 = [[AEPSurface alloc] initWithPath: @"myView#button"];[AEPMobileMessaging updatePropositionsForSurfaces: @[surface1, surface2]];
updatePropositionsForSurfacesWithCompletionHandler
The updatePropositionsForSurfaces API dispatches an event for the Edge network extension to fetch personalization decisions from the AJO campaigns for the provided surfaces array. The returned decision propositions are cached in-memory by the Messaging extension.
If provided, completion will be called on the Messaging extension's background thread once the response has been fully processed. true will be passed to the completion method if a network response was returned and successfully processed.
To retrieve previously cached decision propositions, use getPropositionsForSurfaces API.
Java
Syntax
Copied to your clipboardpublic static void updatePropositionsForSurfaces(@NonNull final List<Surface> surfaces, @Nullable final AdobeCallback<Boolean> callback)
- surfaces is a list of surfaces for which propositions need updating.
- callback
callmethod is invoked withtrueif a network response was returned and successfully processed,falseotherwise
Example
Kotlin
Copied to your clipboardval surface1 = Surface("myActivity#button")val surface2 = Surface("myActivityAttributes")val surfaces = listOf(surface1, surface2)Messaging.updatePropositionsForSurfaces(surfaces) { success ->if (success) {// handle success scenario} else {// handle error scenario}}
Java
Copied to your clipboardfinal Surface surface1 = new Surface("myActivity#button");final Surface surface2 = new Surface("myActivityAttributes");final List<Surface> surfaces = new ArrayList<>();surfaces.add(surface1);surfaces.add(surface2);Messaging.updatePropositionsForSurfaces(surfaces, success -> {if (success) {// handle success scenario} else {// handle error scenario}});
Swift
Syntax
Copied to your clipboardstatic func updatePropositionsForSurfaces(_ surfaces: [Surface], _ completion: ((Bool) -> Void)? = nil)
- surfaces is an array of surfaces for which propositions need updating.
- completion is invoked with
trueif a network response was returned and successfully processed,falseotherwise
Example
Copied to your clipboardlet surface1 = Surface(path: "myView#button")let surface2 = Surface(path: "myViewAttributes")Messaging.updatePropositionsForSurfaces([surface1, surface2]) { success inif success {// handle success scenario} else {// handle error scenario}}
Objective-C
Syntax
Copied to your clipboard+ (void) updatePropositionsForSurfaces: (NSArray<AEPSurface*>* _Nonnull) surfacescompletion: (void (^)(BOOL)) completion;
- surfaces is an array of surfaces for which propositions need updating.
- completion is invoked with
trueif a network response was returned and successfully processed,falseotherwise
Example
Copied to your clipboardAEPSurface* surface1 = [[AEPSurface alloc] initWithPath: @"myView#button"];AEPSurface* surface2 = [[AEPSurface alloc] initWithPath: @"myViewAttributes"];[AEPMobileMessaging updatePropositionsForSurfaces:@[surface1, surface2] completion:^(BOOL success) {if (success) {// handle success scenario} else {// handle error scenario}}];
Java
Syntax
Copied to your clipboardpublic static void updatePropositionsForSurfaces(@NonNull final List<Surface> surfaces, @Nullable final AdobeCallback<Boolean> callback)
- surfaces is a list of surfaces for which propositions need updating.
- callback
callmethod is invoked withtrueif a network response was returned and successfully processed,falseotherwise
Example
Kotlin
Copied to your clipboardval surface1 = Surface("myActivity#button")val surface2 = Surface("myActivityAttributes")val surfaces = listOf(surface1, surface2)Messaging.updatePropositionsForSurfaces(surfaces) { success ->if (success) {// handle success scenario} else {// handle error scenario}}
Java
Copied to your clipboardfinal Surface surface1 = new Surface("myActivity#button");final Surface surface2 = new Surface("myActivityAttributes");final List<Surface> surfaces = new ArrayList<>();surfaces.add(surface1);surfaces.add(surface2);Messaging.updatePropositionsForSurfaces(surfaces, success -> {if (success) {// handle success scenario} else {// handle error scenario}});
Swift
Syntax
Copied to your clipboardstatic func updatePropositionsForSurfaces(_ surfaces: [Surface], _ completion: ((Bool) -> Void)? = nil)
- surfaces is an array of surfaces for which propositions need updating.
- completion is invoked with
trueif a network response was returned and successfully processed,falseotherwise
Example
Copied to your clipboardlet surface1 = Surface(path: "myView#button")let surface2 = Surface(path: "myViewAttributes")Messaging.updatePropositionsForSurfaces([surface1, surface2]) { success inif success {// handle success scenario} else {// handle error scenario}}
Objective-C
Syntax
Copied to your clipboard+ (void) updatePropositionsForSurfaces: (NSArray<AEPSurface*>* _Nonnull) surfacescompletion: (void (^)(BOOL)) completion;
- surfaces is an array of surfaces for which propositions need updating.
- completion is invoked with
trueif a network response was returned and successfully processed,falseotherwise
Example
Copied to your clipboardAEPSurface* surface1 = [[AEPSurface alloc] initWithPath: @"myView#button"];AEPSurface* surface2 = [[AEPSurface alloc] initWithPath: @"myViewAttributes"];[AEPMobileMessaging updatePropositionsForSurfaces:@[surface1, surface2] completion:^(BOOL success) {if (success) {// handle success scenario} else {// handle error scenario}}];


