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
call
method 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, thefail
method 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]]
. AnError
is 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*>*>
. AnNSError
is 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
call
method 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, thefail
method 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]]
. AnError
is 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*>*>
. AnNSError
is 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]];