Skip to content

User data field validation

Luka Ilić edited this page Nov 17, 2026 · 1 revision

User Data Field Validation

Overview

User data fields are validated against the Customer Profiles API (formerly People API) limits before data is sent to the server. Validation is done by the native Android and iOS SDKs, so it became available in a different plugin version for each platform:

Platform Plugin version Bundled native SDK version
Android 9.1.1 Android SDK 14.7.4
iOS 9.2.4 iOS SDK 14.1.3

If any field exceeds its limit, the request is rejected locally, without a network round-trip, and a PlatformException is thrown.

Field Limits

The following limits are enforced based on the Customer Profiles API (formerly People API) specification:

Field Limit Description
firstName 255 characters Person's first name
lastName 255 characters Person's last name
middleName 50 characters Person's middle name
externalUserId 256 characters Unique ID for a person from your external system
emails 100 emails Maximum number of email addresses per person
emails (per address) 255 characters Maximum length of a single email address
phones 100 phone numbers Maximum number of phone numbers per person
customAttributes (per value) 4096 characters Maximum length per custom attribute value

Validation Behavior

  • Validation runs before any HTTP request is made. If any field is invalid, the whole operation is rejected and no partial updates are made.
  • All violations are reported together in a single error.
  • For personalize, user identity is validated before user attributes. If the identity is invalid, only the identity violations are reported and user attributes are not checked.
  • PlatformException.message starts with User data validation failed and contains the full list of violated fields, on both Android and iOS.
  • The same message is logged by the native SDK at error level.
  • Validation cannot be disabled, because the server would reject the same data anyway.

There is no dedicated PlatformException.code for validation errors, and the code differs between Android and iOS. To detect validation errors on both platforms, check the beginning of message rather than code.

Example: Handling Validation Errors

var user = await InfobipMobilemessaging.getUser();
user.firstName = 'a' * 260; // exceeds the 255 limit
user.middleName = 'b' * 55; // exceeds the 50 limit

try {
    await InfobipMobilemessaging.saveUser(user);
} on PlatformException catch (e) {
    if (e.message?.startsWith('User data validation failed') ?? false) {
        print(e.message);
        // User data validation failed:
        //   - firstName exceeds maximum length of 255 characters (actual: 260)
        //   - middleName exceeds maximum length of 50 characters (actual: 55)
        //
        // Please check the field limits at: https://www.infobip.com/docs/api/customer-engagement/people/update-a-person
    } else {
        // handle other errors
    }
}

The same applies to personalization. UserIdentity is checked for externalUserId, emails and phones, and user attributes for firstName, lastName, middleName and customAttributes:

var userIdentity = UserIdentity(externalUserId: 'c' * 300); // exceeds the 256 limit
try {
    await InfobipMobilemessaging.personalize(PersonalizeContext(userIdentity: userIdentity));
} on PlatformException catch (e) {
    if (e.message?.startsWith('User data validation failed') ?? false) {
        print(e.message);
        // User data validation failed:
        //   - externalUserId exceeds maximum length of 256 characters (actual: 300)
        // ...
    }
}

Affected Methods

Field validation is applied to:

  • InfobipMobilemessaging.saveUser(UserData userData)
  • InfobipMobilemessaging.personalize(PersonalizeContext context), including the forceDepersonalize, keepAsLead and setDeviceAsPrimary options

Custom Attribute Validation

Custom attributes have a per-value limit of 4096 characters. The validation checks the string representation of the value. For a list of objects, the length of its JSON representation is checked, because that is what is sent to the server:

user.customAttributes = {
    'description': 'Short description', // valid
    'age': 25,                          // valid
    'isPremium': true,                  // valid
    'longText': 'a' * 5000,             // invalid - exceeds 4096 characters
};

Best Practices

  1. Always catch PlatformException when calling saveUser and personalize, so you can react to validation errors.
  2. Validate data in your UI - consider limiting input lengths so that users can't enter data that exceeds the limits.
  3. Test edge cases - test with data at the boundary limits (e.g., exactly 255 characters) to make sure your app handles limits correctly.

Troubleshooting

Q: Are partial updates allowed if some fields are valid? A: No, validation follows an all-or-nothing approach. If any field is invalid, the entire operation is rejected with no partial updates.

Additional Resources

Clone this wiki locally