Method Reference

Synerise SDK Lifecycle


Initialization


Initializes Synerise SDK.

Declared In

SNRSynerise.h

Method Name

Synerise.initialize(clientApiKey:)

Declaration

func initialize(clientApiKey: String) -> Void

Parameters

Parameter Type Mandatory Default Description
clientApiKey String no - Synerise Client API Key

Return Value

There is no return value.

Examples

let clientApiKey = "YOUR_CLIENT_API_KEY"

Synerise.initialize(clientApiKey: clientApiKey)

Initialize with custom environment


Initializes Synerise SDK with custom environment settings.

Declared In

SNRSynerise.h

Method Name

Synerise.initialize(clientApiKey:baseUrl:)

Declaration

func initialize(clientApiKey: String, baseUrl: String?) -> Void

Parameters

Parameter Type Mandatory Default Description
clientApiKey String no - Synerise Client API Key
baseUrl String no - Synerise API custom environment base URL

Return Value

There is no return value.

Examples

let clientApiKey = "YOUR_CLIENT_API_KEY"
let apiBaseUrl = "YOUR_API_BASE_URL"

Synerise.initialize(clientApiKey: clientApiKey, baseUrl: apiBaseUrl)

Change Client API Key dynamically


Changes Client API Key dynamically.

Declared In

SNRSynerise.h

Method Name

Synerise.changeApiKey(newApiKey)

Declaration

func changeClientApiKey(_ clientApiKey: String) -> Void

Parameters

Parameter Type Mandatory Default Description
clientApiKey String yes - Synerise Client API Key

Return Value

There is no return value.

Set up Debug Mode


Enables/disables console logs from Synerise SDK.

Declared In

SNRSynerise.h

Method Name

Synerise.initialize(clientApiKey:baseUrl:)

Declaration

func setDebugModeEnabled(_ enabled: Bool) -> Void

Parameters

Parameter Type Mandatory Default Description
enabled Bool no - Specifies if console logs are enabled/disabled

Return Value

There is no return value.

Client Authentication


Register Client account


Register a new Client with email, password and optional data.

This method requires the SNRRegisterClientContext object with a Client’s email, password and optional data. Omitted fields are not modified.

Depending of backend configuration, the account may require activation. For details, see registering new user.

Do NOT allow to sign in again (or sign up) when a user is already signed in. Sign the user out first.

Do not create multiple instances nor call this method multiple times before execution. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientRegisterAccountContext.h

Method Name

Client.registerAccount(context:success:failure:)

Declaration

func registerAccount(context: ClientRegisterAccountContext, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
context SNRClientRegisterAccountContext yes - Object with the Client’s email, password, and other optional data
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let agreements: ClientAgreements = ClientAgreements()
agreements.email = true
agreements.sms = true
agreements.push = true
agreements.bluetooth = true
agreements.rfid = true
agreements.wifi = true

let email: String = "YOUR_EMAIL"
let password: String = "YOUR_PASSWORD"

let context: ClientRegisterAccountContext = ClientRegisterAccountContext(email: email, password: password)
context.firstName = "FIRST_NAME"
context.lastName = "LAST_NAME"
context.customId = "CUSTOM_ID"

context.sex = .male
context.phone = "123-456-789"
context.company = "Synerise"
context.address = "Lubostroń 1"
context.city = "Kraków"
context.province = "Małopolskie"
context.zipCode = "30-383"
context.countryCode = "+48"

context.agreements = agreements
context.attributes = ["attribute1": "value1", "attribute2": "value2"]
context.tags = ["tag1", "tag2" "tag3"]

Client.registerAccount(context: context, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Confirm Client account


Confirm a Client account with the confirmation token.

The Method returns the HTTP 400 status code if the account is already confirmed or 404 if the account does not exist. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.confirmAccount(token:success:failure:)

Declaration

func confirmAccount(token: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
token String yes - Confirmation token
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let token: String = "TOKEN"

Client.confirmAccount(token: token, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Activate Client account


Activate a Client with email. This method requires the Client’s email. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.activateAccount(email:success:failure:)

Declaration

func activateAccount(email: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Return Value

There is no return value.

Example

let email: String = "EMAIL"

Client.activateAccount(email: email, success: { (success) in
    // success   
}) { (error) in
    // failure 
}

Sign in a Client


Sign in a client in order to obtain the JWT token, which can be used in subsequent requests.

The token is valid for 1 hour (unless configured otherwise in Synerise) and the SDK will refresh the token before each call if it is expiring soon (but still valid).

The method requires valid and non-null email and password.

Do NOT allow to sign in again (or sign up) when a user is already signed in. Sign the user out first.

Do not create multiple instances nor call this method multiple times before execution. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.signIn(email:password:success:failure:)

Declaration

func signIn(email: String, password: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
email String yes - Client’s email
password String yes - Client’s password
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let email: String = "EMAIL"
let password: String = "PASSWORD"

Client.signIn(email: email, password: password, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Discussion

Authenticate Client by OAuth


Use this method to sign in with an OAuth authorization token.

The HTTP 401 status code is returned if the provided access token and/or API Key is invalid. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientOAuthContext.h

Method Name

Client.authenticateByOAuth(accessToken:authID:success:failure:)

Declaration

func authenticateByOAuth(accessToken: String, authID: String?, context: ClientOAuthContext?, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
accessToken String yes - OAuth Access Token
authID String no - Custom identity for authorization
context SNRClientOAuthContext no - Object with authorization agreements and optional attributes
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let agreements: ClientAgreements = ClientAgreements()
agreements.email = true
agreements.sms = true
agreements.push = true
agreements.bluetooth = true
agreements.rfid = true
agreements.wifi = true

let context: ClientOAuthContext = ClientOAuthContext()
context.agreements = agreements
context.attributes = ["attribute1": "value1", "attribute2": "value2"]

let accessToken: String = "ACCESS_TOKEN"
let authID: String = "AUTH_ID"

Client.authenticateByOAuth(accessToken: accessToken, authID: authID, context: context, success: { (success) in
    // success
}) { (error) in
    // failure   
}

Authenticate Client by Facebook with registration


Use this method to sign in with Facebook (for Clients that are not registered yet)

The HTTP 401 status code is returned if the provided Facebook token and/or API Key is invalid.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientFacebookAuthenticationContext.h

Method Name

Client.authenticateByFacebook(facebookToken:authID:success:failure:)

Declaration

func authenticateByFacebook(facebookToken: String, authID: String?, context: ClientFacebookAuthenticationContext?, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
facebookToken String yes - Facebook Access Token
authID String no - Custom identity for authorization
context SNRClientFacebookAuthenticationContext no - Object with authorization agreements and optional attributes
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let agreements: ClientAgreements = ClientAgreements()
agreements.email = true
agreements.sms = true
agreements.push = true
agreements.bluetooth = true
agreements.rfid = true
agreements.wifi = true

let context: ClientFacebookAuthenticationContext = ClientFacebookAuthenticationContext()
context.agreements = agreements
context.attributes = ["attribute1": "value1", "attribute2": "value2"]

guard let facebookToken = FBSDKAccessToken.current()?.tokenString else {
    return
}
let authID: String = "AUTH_ID"

Client.authenticateByFacebook(facebookToken: fa, authID: authID, context: context, success: { (success) in
    // success
}) { (error) in
    // failure
}

Authenticate Client by Facebook without registration


Use this method to sign in with already registered Facebook account.

The HTTP 401 status code is returned if there is no associated account with the provided facebook token. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.authenticateByFacebookIfRegistered(facebookToken:authID:success:failure:)

Declaration

func authenticateByFacebookIfRegistered(facebookToken: String, authID: String?, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
facebookToken String yes - Facebook Access Token
authID String no - Custom identity for authorization
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

guard let facebookToken = FBSDKAccessToken.current()?.tokenString else {
    return
}
let authID: String = "AUTH_ID"

Client.authenticateByFacebookIfRegistered(facebookToken: facebookToken, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Check if a Client is signed in


Check if a Client is signed in (their token is authorized).

Declared In

SNRClient.h

Method Name

Client.isSignedIn()

Declaration

func isSignedIn() -> Bool

Return Value

true if the user is signed in, otherwise return false.

Example

let isSignedIn: Bool = Client.isSignedIn()

Sign out Client


Signing a Client out clears the Client’s JWT token.

Declared In

SNRClient.h

Method Name

Client.signOut()

Declaration

func signOut() -> Void

Return Value

There is no return value.

Example

Client.signOut()

Client Account Management


Get Client account information


Use this method to get a Client’s account information.

Declared In

SNRClient.h

SNRClientAccountInformation.h

Method Name

Client.getAccount(success:failure:)

Declaration

func getAccount(success: ((SNRClientAccountInformation) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

Client.getAccount(success: { (clientAccountInformation) in
    // success
}) { (error) in
    // failure
}

Update Client account information


Use this method to update a Client’s account information.

This method requires the UpdateAccountInformation object with the Client’s account information. Omitted fields are not modified.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientUpdateAccountContext.h

Method Name

Client.updateAccount(success:failure:)

Declaration

func updateAccount(context: ClientUpdateAccountContext, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
context SNRClientUpdateAccountContext yes - Object with client’s email, password, and other optional data
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let agreements: ClientAgreements = ClientAgreements()
agreements.email = true
agreements.sms = true
agreements.push = true
agreements.bluetooth = true
agreements.rfid = true
agreements.wifi = true

let context: ClientUpdateAccountContext = ClientUpdateAccountContext()
context.email = "hello@synerise.com"
context.phone = "123-456-789"
context.customId = "CUSTOM_ID"
context.uuid = "UUID"

context.firstName = "FIRST_NAME"
context.lastName = "LAST_NAME"
context.displayName = "DISPLAY_NAME"
context.sex = .male
context.company = "Synerise"
context.address = "Lubostroń 1"
context.city = "Kraków"
context.province = "Małopolskie"
context.zipCode = "30-383"
context.countryCode = "+48"
context.birthDate = "01-01-2019"
context.avatarUrl = "http://www.synerise.com"

context.agreements = agreements
context.attributes = ["attribute1": "value1", "attribute2": "value2"]
context.tags = ["tag1", "tag2" "tag3"]

Client.updateAccount(context: context, success: { (success) in
    // success
}) { (error) in
    // failure
}

Change Client’s account password


Use this method to change a Client’s password.

Returns the HTTP 403 status code if provided old password is invalid.

Declared In

SNRClient.h

Method Name

Client.changePassword(password:oldPassword:success:failure:)

Declaration

func changePassword(password: String, oldPassword: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
password String yes - Client’s new password
oldPassword String yes - Client’s old password
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let newPassword: String = "NEW_PASSWORD"
let oldPassword: String = "OLD_PASSWORD"

Client.changePassword(password: newPassword, oldPassword: oldPassword, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Request password reset for Client account


Request a Client’s password reset with email. The Client will receive a token at the provided email address. That token is then used for Client.confirmResetPassword.

This method requires the Client’s email. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

SNRClientPasswordResetRequestContext.h

Method Name

Client.requestPasswordReset(context:success:failure:)

Declaration

func requestPasswordReset(context: ClientPasswordResetRequestContext, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
context SNRClientPasswordResetRequestContext yes - Object with the Client’s email
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let email: String = "EMAIL"
let context: ClientPasswordResetRequestContext = ClientPasswordResetRequestContext(email: email)

Client.requestPasswordReset(context: context, success: { (success) in
    // success
}, failure: { (error) in
    // failure
}) 

Confirm password reset for Client account


Confirm a Client’s password reset with the new password and token provided by Client.requestPasswordReset(email).

This method requires the Client’s new password and the confirmation token received by e-mail.

This method is a global operation and does not require authorization.

Declared In

SNRClient.h

SNRClientPasswordResetConfirmationContext.h

Method Name

Client.confirmResetPassword(context:success:failure:)

Declaration

func confirmResetPassword(context: ClientPasswordResetConfirmationContext, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
context SNRClientPasswordResetConfirmationContext yes - Object with client’s password and token
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let password: String = "PASSWORD"
let token: String = "TOKEN"
let context: ClientPasswordResetConfirmationContext = ClientPasswordResetConfirmationContext(password: password, token: token)

Client.confirmResetPassword(context: context, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Request email change for Client account


Use this method to request a Client’s email change.

Returns the HTTP 403 status code if the provided UUID does not exist or the password is invalid.

Declared In

SNRClient.h

Method Name

Client.requestEmailChange(email:password:success:failure:)

Declaration

func requestEmailChange(email:String, password: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
email String yes - Client’s new email
password String yes - Client’s password
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let email: String = "EMAIL"
let password: String = "PASSWORD"

Client.requestEmailChange(email: email, password: password, success: { success in
    // success
}) { (error) in
    // failure
}

Request email change by Facebook


Use this method to request a Client’s email change by Facebook.

Returns HTTP 403 status code if the provided UUID does not exist.

Declared In

SNRClient.h

Method Name

Client.requestEmailChangeByFacebook(email:password:success:failure:)

Declaration

func requestEmailChangeByFacebook(email: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
email String yes - Client’s new email
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let email: String = "EMAIL"

Client.requestEmailChange(email: email, success: { success in
    // success
}) { (error) in
    // failure
}

Confirm email change for Client account


Use this method to confirm an email change.

Returns the HTTP 403 status code if the provided token is invalid.

Declared In

SNRClient.h

Method Name

Client.confirmEmailChange(token:success:failure:)

Declaration

func confirmEmailChange(token: String, newsletterAgreement: Bool, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
token String yes - Client’s token provided by email
newsletterAgreement Bool yes - Agreement for newsletters to the provided email
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let token: String = "TOKEN"

Client.confirmEmailChange(token: token, success: { _ in
    // success
}) { (error) in
    // failure
}

Request phone update on Client account


Use this method to request a phone number update. This action requires additional validation by PIN code.

Returns the HTTP 403 status code if the provided UUID does not exist or the password is invalid.

Declared In

SNRClient.h

Method Name

Client.requestPhoneUpdate(phone:success:failure:)

Declaration

func requestPhoneUpdate(phone: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
phone String yes - Client’s new phone number
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let phone: String = "123-456-789"

Client.requestPhoneUpdate(phone: phone, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Confirm phone update on Client account


Use this method to confirm a phone number update. This action requires the new phone number and confirmation code as parameters.

Returns the HTTP 403 status code if the provided UUID does not exist or the password is invalid.

Declared In

SNRClient.h

Method Name

Client.confirmPhoneUpdate(phone:confirmationCode:success:failure:)

Declaration

func confirmPhoneUpdate(phone: String, confirmationCode: String, smsAgreement: Bool, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
phone String yes - New phone number
confirmationCode String yes - Client’s confirmation code received by phone
smsAgreement Bool yes - Agreement for SMS marketing to the provided number
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let phone: String = "123-456-789"
let confirmationCode: String = "CONFIRMATION_CODE"

Client.confirmPhoneUpdate(phone: phone, confirmationCode: confirmationCode, smsAgreement: true, success: { (success) in
    // success
}) { (error) in
    // failure
}

Delete Client account


Use this method to delete a Client’s account.

HTTP 403 status code will be returned if provided password is invalid.

Declared In

SNRClient.h

Method Name

Client.deleteAccount(success:failure:)

Declaration

func deleteAccount(password: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
password String yes - Client’s password
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let password: String = "PASSWORD"

Client.deleteAccount(password: password, success: { (success) in
    // success
}) { (error) in
    // failure
}

Delete Client account by Facebook


Use this method to delete account by Facebook.

Returns:

  • HTTP 400 status code if the provided data is invalid.
  • HTTP 403 status code if the provided token is invalid.
  • HTTP 404 status code if the Facebook user does not exist.

Declared In

SNRClient.h

Method Name

Client.deleteAccountByFacebook(facebookToken:success:failure:)

Declaration

func deleteAccountByFacebook(facebookToken: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
facebookToken String yes - Token from an active Facebook session
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

guard let facebookToken = FBSDKAccessToken.current()?.tokenString else {
    return
}

Client.deleteAccountByFacebookToken(facebookToken: facebookToken, success: { (success) in
    // success
}, failure: { (error) in
    // failure
})

Recognize anonymous user


Method to recognize anonymous users and save personal information in their CRM entries.

Declared In

SNRClient.h

Method Name

Client.recognizeAnonymous(email:customIdentify:parameters:)

Declaration

func recognizeAnonymousWithEmail(email: String?, customIdentify: String?, parameters: [AnyHashable: Any]?) -> Void

Parameters

Parameter Type Mandatory Default Description
email String no - Client’s email
customIdentify String no - Client’s custom identifier
parameters [AnyHashable: Any] no - Client’s custom parameters

Return Value

There is no return value.

Examples

let email = "EMAIL"
let customIdentify = "CUSTOM_IDENTIFIER"
let parameters = ["key": "value"]

Client.recognizeAnonymous(email: email, customIdentify: customIdentify, parameters: parameters)

Client Session


Retrieve Client token


Retrieves the Client’s current, active token.

An error is returned when the Client is not logged in or the token has expired and cannot be refreshed.

Declared In

SNRClient.h

SNRToken.h SNRTokenOrigin.h

Method Name

Client.retrieveToken(success:failure:)

Declaration

func retrieveToken(success: ((SNRToken) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

Client.retrieveToken(success: { (token) in
    // success

    let tokenString: String = token.tokenString
    let tokenOrigin: TokenOrigin = token.tokenOrigin

}, failure: { (error) in
    // failure
})

Get Client token (deprecated)


Retrieves the Client’s current, active token.

An error is returned when the Client is not logged in or the token has expired and cannot be refreshed.

Declared In

SNRClient.h

SNRTokenOrigin.h

Method Name

Client.getToken(success:failure:)

Declaration

func getToken(success: ((String, TokenOrigin) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

Client.getToken(success: { (token, origin) in
    // success
}) { (error) in
    // failure
}

Get current Client UUID


Retrieve the Client’s current UUID.

HTTP 403 status code is returned if the provided password is invalid.

Declared In

SNRClient.h

Method Name

Client.getUUID()

Declaration

func getUUID() -> String

Return Value

Method returns NSString/String with the Client’s UUID.

Example

let clientUUID: String = Client.getUUID()

Regenerate Client


Regenerate the UUID and clear the authentication token, login session, custom email, and custom identifier.

This operation works only if the Client is anonymous.

Declared In

SNRClient.h

Method Name

Client.regenerateUUID()

Declaration

func regenerateUUID() -> Void

Return Value

true if the Current Client is anonymous and the operation succeed, false otherwise.

Push Notifications


Register for Push Notifications


Use this method to pass the Firebase Token to Synerise for notifications.

Declared In

SNRClient.h

Method Name

Client.registerForPush(registrationToken:success:failure:)

Declaration

func registerForPush(registrationToken: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
registrationToken String yes - Firebase Token

Return Value

There is no return value.

Example

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    Client.registerForPush(registrationToken: fcmToken, success: { (_) in
        // success
    }, failure: { (error) in
        // failure
    })
}

Check if Push Notification is from Synerise


Verifies that a notification was sent by Synerise.

Declared In

SNRSynerise.h

Method Name

Synerise.isSyneriseNotification(_:)

Declaration

func isSyneriseNotification(_ userInfo: [AnyHashable: Any]) -> Void

Parameters

Parameter Type Mandatory Default Description
userInfo [AnyHashable: Any] no - Key-Value map of data

Return Value

There is no return value.

Examples

//MARK: - UNUserNotificationCenterDelegate

extension NotificationService: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        let isSyneriseNotification = Synerise.isSyneriseNotification(userInfo)
        if isSyneriseNotification == true {
            // notification is from Synerise
        }
    }
}

Check if Push Notification is a Simple Push Campaign


Verifies that a notification was sent by Synerise and that it’s a Simple Push.

Declared In

SNRSynerise.h

Method Name

Synerise.isSyneriseSimplePush(_:)

Declaration

func isSyneriseSimplePush(_ userInfo: [AnyHashable: Any]) -> Void

Parameters

Parameter Type Mandatory Default Description
userInfo [AnyHashable: Any] no - Key-Value map of data

Return Value

There is no return value.

Examples

//MARK: - UNUserNotificationCenterDelegate

extension NotificationService: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        let isSyneriseNotification = Synerise.isSyneriseNotification(userInfo)
        if isSyneriseNotification == true {
            // notification is from Synerise

            let isSyneriseSimplePush = Synerise.isSyneriseSimplePush(userInfo)
            if isSyneriseSimplePush == true {
                // notification is Synerise Simple Push Campaign
            }
        }
    }
}

Check if Push Notification is a Banner Campaign


Verifies that a notification was sent by Synerise and that it’s a Banner.

Declared In

SNRSynerise.h

Method Name

Synerise.isSyneriseBanner(_:)

Declaration

func isSyneriseBanner(_ userInfo: [AnyHashable: Any]) -> Void

Parameters

Parameter Type Mandatory Default Description
userInfo [AnyHashable: Any] no - Key-Value map of data

Return Value

There is no return value.

Examples

//MARK: - UNUserNotificationCenterDelegate

extension NotificationService: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        let isSyneriseNotification = Synerise.isSyneriseNotification(userInfo)
        if isSyneriseNotification == true {
            // notification is from Synerise

            let isSyneriseBanner = Synerise.isSyneriseBanner(userInfo)
            if isSyneriseBanner == true {
                // notification is Synerise Banner Campaign
            }
        }
    }
}

Check if Push Notification is a Silent Command


Verifies that a notification was sent by Synerise and that it’s a Silent Command.

Declared In

SNRSynerise.h

Method Name

Synerise.isSyneriseSilentCommand(_:)

Declaration

func isSyneriseSilentCommand(_ userInfo: [AnyHashable: Any]) -> Void

Parameters

Parameter Type Mandatory Default Description
userInfo [AnyHashable: Any] no - Key-Value map of data

Return Value

There is no return value.

Examples

//MARK: - UNUserNotificationCenterDelegate

extension NotificationService: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        let isSyneriseNotification = Synerise.isSyneriseNotification(userInfo)
        if isSyneriseNotification == true {
            // notification is from Synerise

            let isSyneriseSilentCommand = Synerise.isSyneriseSilentCommand(userInfo)
            if isSyneriseSilentCommand == true {
                // notification is Synerise Silent Command
            }
        }
    }
}

Check if Push Notification is a Silent SDK Command


Verifies that a notification was sent by Synerise and that it’s a Silent SDK Command.

Declared In

SNRSynerise.h

Method Name

Synerise.isSyneriseSilentSDKCommand(_:)

Declaration

func isSyneriseSilentSDKCommand(_ userInfo: [AnyHashable: Any]) -> Void

Parameters

Parameter Type Mandatory Default Description
userInfo [AnyHashable: Any] no - Key-Value map of data

Return Value

There is no return value.

Examples

//MARK: - UNUserNotificationCenterDelegate

extension NotificationService: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        let isSyneriseNotification = Synerise.isSyneriseNotification(userInfo)
        if isSyneriseNotification == true {
            // notification is from Synerise

            let isSyneriseSilentSDKCommand = Synerise.isSyneriseSilentSDKCommand(userInfo)
            if isSyneriseSilentSDKCommand == true {
                // notification is Synerise Silent SDK Command
            }
        }
    }
}

Handle Synerise Push Notification


Handles the notification payload and starts activity.

Declared In

SNRSynerise.h

Method Name

Synerise.handleNotification(_:)

Declaration

func handleNotification(_ userInfo: [AnyHashable: Any]) -> Void

Parameters

Parameter Type Mandatory Default Description
userInfo [AnyHashable: Any] no - Key-Value map of data

Return Value

There is no return value.

Examples

//MARK: - UNUserNotificationCenterDelegate

extension NotificationService: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        let isSyneriseNotification = Synerise.isSyneriseNotification(userInfo)
        if isSyneriseNotification == true {
            // notification is from Synerise

            Synerise.handleNotification(userInfo)
        }
    }
}

Handle Synerise Push Notification with action


Handles the notification payload, including information about an action performed by a user, and starts activity.

Declared In

SNRSynerise.h

Method Name

Synerise.handleNotification(_:actionIdentifier:)

Declaration

func handleNotification(_ userInfo: [AnyHashable: Any], actionIdentifier: String) -> Void

Parameters

Parameter Type Mandatory Default Description
userInfo [AnyHashable: Any] no - Key-Value map of data
actionIdentifier String no - Identifier of action received from notification response

Return Value

There is no return value.

Examples

//MARK: - UNUserNotificationCenterDelegate

extension NotificationService: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        let actionIdentifier = response.actionIdentifier

        let isSyneriseNotification = Synerise.isSyneriseNotification(userInfo)
        if isSyneriseNotification == true {
            // notification is from Synerise

            Synerise.handleNotification(userInfo, actionIdentifier: actionIdentifier)
        }
    }
}

Tracking


Set Custom Identifier for events


You can pass a custom identifier to match your users in our CRM. The custom identifier is sent in the parameters of every event.

Declared In

SNRTracker.h

Method Name

Tracker.setCustomIdentifier(customIdentifier:)

Declaration

func setCustomIdentifier(customIdentifier: String) -> Void

Parameters

Parameter Type Mandatory Default Description
customIdentifier String yes - Client’s custom identifier

Return Value

There is no return value.

Set Custom Email for events


You can pass a custom email to match your users in our CRM. The custom email is sent in the parameters of every event.

Declared In

SNRTracker.h

Method Name

Tracker.setCustomEmail(customEmail:)

Declaration

func setCustomEmail(customEmail: String) -> Void

Parameters

Parameter Type Mandatory Default Description
customEmail String yes - Client’s custom email

Return Value

There is no return value.

Send event


Use this method to send an event.

The tracker caches and enqueues all your events locally, so they all will be sent eventually.

Declared In

SNRTracker.h

  • SNRTrackerParams.h
  • SNRTrackerParamsBuilder
  • SNREvent.h
  • SNRCustomEvent.h

Method Name

Tracker.send(_: Event)

Declaration

func send(_: Event) -> Void

Parameters

Parameter Type Mandatory Default Description
event SNREvent yes - SNREvent object

Return Value

There is no return value.

Examples

You may use standard objects in SDK, for example SNRAddedProductToCartEvent that represents a ‘client added product to cart’ event:

let event: AddedProductToCartEvent = AddedProductToCartEvent(label: "Product added!", sku: "12345", finalPrice: UnitPrice(amount: 100.0), quantity: 1)
event.setCategory("Smartphones")
event.setName("iPhone")
event.setProducer("Apple")

Tracker.send(event)

You can also pass additional parameters along with SNRAddedProductToCartEvent and other events, like in the example below:

let params: TrackerParams = TrackerParams.make { (builder) in
    builder.setString("12345", forKey: "snr_sku")
    builder.setInt(1, forKey: "snr_quantity")
    builder.setDouble(100.0, forKey: "snr_finalPrice")
}

let event: AddedProductToCartEvent = AddedProductToCartEvent(label: "Product added!", sku: "12345", finalPrice: UnitPrice(amount: 100.0), quantity: 1, params: params)
event.setCategory("Smartphones")
event.setName("iPhone")
event.setProducer("Apple")

Tracker.send(event)

If you want to track a fully customizable event, you should use SNRCustomEvent:

let params: TrackerParams = TrackerParams.make { (builder) in
    builder.setString("12345", forKey:"key_string");
    builder.setInt(1, forKey:"key_integer");
    builder.setDouble(1.0, forKey:"key_double");
    builder.setFloat(1.0, forKey:"key_float");
    builder.setBool(true, forKey:"key_bool");
    builder.setObject(["key": "value"], forKey:"key_object");
}

let event: CustomEvent = CustomEvent(label: "custom event", action: "custom event action", params: params)

Tracker.send(event)

Flush events from Tracker


Forces sending the events from the queue to the server. This method is a global operation and does not require authorization.

Declared In

SNRTracker.h

Method Name

Tracker.flushEvents(completionHandler:)

Declaration

func flushEvents(completionHandler: (() -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
completionHandler Block/Closure no - Block/closure to be executed when the operation finishes

Return Value

There is no return value.

Content


Get Document


Gets a document that is defined for the provided slug.

Declared In

SNRContent.h

Method Name

Content.getDocument(slug:success:failure:)

Declaration

func getDocument(slug: String, success: (([AnyHashable: Any]) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
slug String yes - Identifies a specific document
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let slug = "similar"

Content.getDocument(slug: slug, success: { document in
    // success
}) { error in
    // failure
}

Get Recommendations


Gets recommendations that are defined for the provided options.

Declared In

SNRContent.h

SNRRecommendationOptions.h

Method Name

Content.getDocument(slug:success:failure:)

Declaration

func getRecommendations(options: RecommendationOptions, success: (RecommendationResponse) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
options SNRRecommendationOptions yes - Options for recommendations
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let options: RecommendationOptions = RecommendationOptions()
options.slug = "similar"
options.productID = "1"

Content.getRecommendations(options: options, success: { (recommendationResponse) in
    // success
}) { (error) in
    // failure
}

Promotions


Get all promotions of a Client


Use this method to get all available promotions that are defined for this Client.

Declared In

SNRPromotions.h

Method Name

Promotions.getPromotions(success:failure:)

Declaration

func getPromotions(success: ((PromotionResponse) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

Promotions.getPromotions(success: { (promotionResponse) in
    // success
    print(promotionResponse.items)
}, failure: { (error) in
    // failure
})

Get promotions with query parameters


Use this method to get promotions that match the parameters defined in an API query.

Declared In

SNRPromotions.h

Method Name

Promotions.getPromotions(apiQuery:success:failure:)

Declaration

func getPromotions(apiQuery: PromotionsApiQuery, success: ((PromotionResponse) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
apiQuery SNRPromotionsApiQuery no - Object that stores all query parameters
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let apiQuery = PromotionsApiQuery()
apiQuery.types = [SNR_PROMOTION_TYPE_GENERAL]
apiQuery.statuses = [SNR_PROMOTION_STATUS_ACTIVE, SNR_PROMOTION_STATUS_ASSIGNED]
apiQuery.types = [SNR_PROMOTION_TYPE_GENERAL]
apiQuery.sorting = [
    [SNR_PROMOTION_SORTING_KEY_EXPIRE_AT: SNR_API_QUERY_SORTING_ASC],
    [SNR_PROMOTION_SORTING_KEY_TYPE: SNR_API_QUERY_SORTING_DESC]
]
apiQuery.limit = 50
apiQuery.page = 1
apiQuery.includeMeta = true

Promotions.getPromotions(apiQuery: apiQuery, success: { (promotionResponse) in
    // success
}, failure: { (error) in
    // failure
})

Get promotion by UUID


Use this method to get the promotion with the specified UUID.

Declared In

SNRPromotions.h

Method Name

Promotions.getPromotion(uuid:success:failure:)

Declaration

func getPromotion(uuid: String, success: ((PromotionResponse) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
uuid String yes - UUID of the promotion
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let UUID: String = "UUID"

Promotions.getPromotion(uuid: UUID, success: { (promotion) in
    // success
    print(promotion.code)
    print(promotion.discountValue)
}, failure: { (error) in
    // failure
})

Get promotion by code


Use this method to get the promotion with the specified code.

Declared In

SNRPromotions.h

Method Name

Promotions.getPromotion(code:success:failure:)

Declaration

func getPromotion(code: String, success: ((PromotionResponse) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
code String true - Code of the promotion
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let code: String = "CODE"

Promotions.getPromotion(code: code, success: { (promotion) in
    // success
    print(promotion.code)
    print(promotion.discountValue)
}, failure: { (error) in
    // failure
})

Activate promotion by UUID


Use this method to activate the promotion with the specified UUID.

Declared In

SNRPromotions.h

Method Name

Promotions.activatePromotion(uuid:success:failure:)

Declaration

func activatePromotion(uuid: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
uuid String yes - UUID of the promotion
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let UUID: String = "UUID"

Promotions.activatePromotion(uuid: UUID, success: { (isSuccess) in
    // success
}, failure: { (error) in
    // failure
})

Activate promotion by code


Use this method to activate the promotion with the specified code.

Declared In

SNRPromotions.h

Method Name

Promotions.activatePromotion(code:success:failure:)

Declaration

func activatePromotion(code: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
code String yes - Code of the promotion
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let code: String = "CODE"

Promotions.activatePromotion(code: code, success: { (isSuccess) in
    // success
}, failure: { (error) in
    // failure
})

Deactivate promotion by UUID


Use this method to de-activate the promotion with the specified UUID.

Declared In

SNRPromotions.h

Method Name

Promotions.deactivatePromotion(uuid:success:failure:)

Declaration

func deactivatePromotion(uuid: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
uuid String yes - UUID of the promotion
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let UUID: String = "UUID"

Promotions.deactivatePromotion(uuid: UUID, success: { (isSuccess) in
    // success
}, failure: { (error) in
    // failure
})

Deactivate promotion by code


Use this method to de-activate the promotion with the specified code.

Declared In

SNRPromotions.h

Method Name

Promotions.deactivatePromotion(code:success:failure:)

Declaration

func deactivatePromotion(code: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
code String yes - Code of the promotion
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let code: String = "CODE"

Promotions.deactivatePromotion(code: code, success: { (isSuccess) in
    // success
}, failure: { (error) in
    // failure
})

Vouchers


Get or assign voucher from pool


Use this method to get voucher code only once or assign voucher with provided pool UUID for the client.

Declared In

SNRPromotions.h

Method Name

Promotions.getOrAssignVoucher(poolUUID:success:failure:)

Declaration

func getOrAssignVoucher(poolUUID: String, success: ((SNRAssignVoucherResponse) -> ()), failure: ((Error) -> ()))

Parameters

Parameter Type Mandatory Default Description
poolUUID String no - Pool’s universally unique identifier
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let poolUUID: String = "POOL_UUID"

Promotions.getOrAssignVoucher(poolUUID: poolUUID, success: { (assignVoucherResponse) in
    // success
failure: { (error) in
    // failure
})

Assign voucher code from pool


Use this method to assign voucher with provided pool UUID for the client.

Every request returns different code until the pool is empty.

Declared In

SNRPromotions.h

Method Name

Promotions.assignVoucherCode(poolUUID:success:failure:)

Declaration

func assignVoucherCode(poolUUID: String, success: ((SNRAssignVoucherResponse) -> ()), failure: ((Error) -> ()))

Parameters

Parameter Type Mandatory Default Description
poolUUID String no - Pool’s universally unique identifier
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let poolUUID: String = "POOL_UUID"

Promotions.assignVoucherCode(poolUUID: poolUUID, success: { (assignVoucherResponse) in
    // success
}, failure: { (error) in
    // failure
})

Get Client-assigned voucher codes


Use this method to get client’s voucher codes.

Declared In

SNRPromotions.h

Method Name

Promotions.getAssignedVoucherCodes(success:failure:)

Declaration

func getAssignedVoucherCodes(success: ((SNRVoucherCodesResponse) -> ()), failure: ((Error) -> ()))

Parameters

Parameter Type Mandatory Default Description
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

Promotions.getAssignedVoucherCodes(success: { (voucherCodesResponse) in
    // success
}, failure: { (error) in
    // failure
})

😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.