Performing an attributes operation is done by using the attributes client that can be accessed from the MceSdk class. To set or update attributes, pass a list of attributes, each of which includes a name and a value. The list can have different subtypes of attributes. To delete, just pass a list of strings which correspond to the names of the attributes you want to delete for that user.

Note: Attribute updates can be non-intuitive. They are cached both on the device and the server, which can lead to issues if you update attributes from the SDK and via API.

In addition, lookup key attributes may not be updated by SDK. See Understanding user attributes for further details and limitations of using attributes from the SDK.

Example

import com.ibm.mce.sdk.api.attribute.Attribute;
import com.ibm.mce.sdk.api.attribute.StringAttribute;
import com.ibm.mce.sdk.api.attribute.NumberAttribute;
import com.ibm.mce.sdk.api.attribute.BooleanAttribute;
// DateAttribute currently does not work
//import com.ibm.mce.sdk.api.attribute.DateAttribute;
import com.ibm.mce.sdk.api.attribute.AttributesOperation;

// To set or update one or more attributes
List < Attribute > attributes = new LinkedList < Attribute > ();
// attributes can also be ArrayList or any other List implementation
attributes.add(new StringAttribute("hobby", "movies"));
attributes.add(new NumberAttribute("age", 40));
attributes.add(new BooleanAttribute("getsCatalogue", false));
// DateAttribute currently does not work
// attributes.add(new DateAttribute("birthday", new Date()));

try {
    MceSdk.getQueuedAttributesClient().updateUserAttributes(
        getApplicationContext(),
        attributes);
} catch (JSONException jsone) {
    // if this happens it's an SDK defect
}


// To delete one or more attributes
List < String > attributeKeys = new ArrayList < String > ();
attributeKeys.add("hobby");
attributeKeys.add("getsCatalogue");
try {
    MceSdk.getQueuedAttributesClient().deleteUserAttributes(
        getApplicationContext(),
        attributeKeys);
} catch (JSONException jsone) {
    // if this happens it's an SDK defect
}

Go Back to the Mobile App Messaging home page.

Join The Discussion

Your email address will not be published. Required fields are marked *