Profile

Manage a Sahha user profile

🚧

Creating a Profile

Each user of your app will be assigned a Sahha Profile for analyzation. This is not handled by the Sahha SDK. Please refer to the separate Sahha API documentation for steps to generate profiles and profile tokens.

Getting Started with Sahha


Authenticate

The Sahha SDK must be authenticated in order to connect to the Sahha API. Do this once per user profile. Once the user is successfully authenticated, the SDK will take care of automatically refreshing expired tokens.

Sahha.authenticate(token: "PROFILE_TOKEN", refreshToken: "REFRESH_TOKEN")
Sahha.authenticate(profileToken: "PROFILE_TOKEN", refreshToken:  "REFRESH_TOKEN") { error, success ->
    if (success) greeting = "Successful"
    else greeting = error ?: "Failed"
}
SahhaFlutter.authenticate("PROFILE_TOKEN", "REFRESH_TOKEN")
  .then((success) => {
    debugPrint(success.toString())
  })
  .catchError((error, stackTrace) => {
    debugPrint(error.toString())
  });
Sahha.authenticate(
  "PROFILE_TOKEN",
  "REFRESH_TOKEN",
  (error: string, success: boolean) => {
    console.log(`Success: ${success}`);
    if (error) {
      console.error(`Error: ${error}`);
    }
  }
);
Sahha.authenticate({
  profileToken: "PROFILE_TOKEN",
  refreshToken: "REFRESH_TOKEN",
})
  .then((data) => {
    console.log(`Success: ${data.success}`);
  })
  .catch((error: Error) => {
    console.error(error);
  });

Demographic

Each authenticated profile includes an optional demographic which can be used to increase the accuracy of analyzation. This data is not collected automatically. Your app can choose to GET or POST this demographic to the Sahha API.

👍

All values are optional

String values are case insensitive (for example: 'us' and 'US' are equal and valid).

age : Int

Age must be a valid Int between 1 - 99.

gender : String

Gender must be a valid String from this list:

  • 'male'
  • 'female'
  • 'gender diverse'

country : String

Country must be a valid 2 character ISO String from this list:

ISO Country Codes{:target="_blank"}

birthCountry : String

Birth Country must be a valid 2 character ISO String from this list:

ISO Country Codes{:target="_blank"}

ethnicity : String

Any String value.

occupation : String

Any String value.

industry : String

Any String value.

incomeRange : String

Any String value.

education : String

Any String value.

relationship : String

Any String value.

locale : String

Any String value.

livingArrangement : String

Any String value.

birthDate : String

Birth Date must be a String in the format 'YYYY-MM-DD'. For example, '1990-05-20'.


MODEL

// All values are optional

public struct SahhaDemographic: Codable {
    public var age: Int?
    public var gender: String? // "male", "female", "gender diverse"
    public var country: String? // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var birthCountry: String?  // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var ethnicity: String? // any string
    public var occupation: String? // any string
    public var industry: String? // any string
    public var incomeRange: String? // any string
    public var education: String? // any string
    public var relationship: String? // any string
    public var locale: String? // any string
    public var livingArrangement: String? // any string
    public var birthDate: String? // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}
// All values are optional

class SahhaDemographic {
    public var age: Int?
    public var gender: String? // "male", "female", "gender diverse"
    public var country: String? // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var birthCountry: String?  // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var ethnicity: String? // any string
    public var occupation: String? // any string
    public var industry: String? // any string
    public var incomeRange: String? // any string
    public var education: String? // any string
    public var relationship: String? // any string
    public var locale: String? // any string
    public var livingArrangement: String? // any string
    public var birthDate: String? // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}
// All values are optional

var demographic = {
  "age" : 35, // int
  "gender" : "Female", // string, "Male", "Female", "Gender Diverse"
  "country" : "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  "birthCountry" : "UK" // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
};
// All values are optional

const demographic = {
  age: 35, // number
  gender: "Female", // string, "Male", "Female", "Gender Diverse",
  country: "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry: "UK", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthDate: "1990-05-20" // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}
// All values are optional

const demographic: SahhaDemographic = {
  age: 35, // number
  gender: "Female", // string, "Male", "Female", "Gender Diverse",
  country: "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry: "UK", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthDate: "1990-05-20", // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
};

POST

let demographic = SahhaDemographic(age: 21, gender: "female", country: "uk", birthCountry: "au")

Sahha.postDemographic(demographic) { error, success in
    if let error = error {
        print(error)
    }
    print(success)
}
var demographic = SahhaDemographic(age: 21, gender: "female", country: "uk", birthCountry: "au")

Sahha.postDemographic(demographic) { error, success ->
    if (error != null) {
        println(error)
    } else {
        println(success.toString())
    }
}
var demographic = {
  "age" : 35, // int
  "gender" : "Female", // string, "Male", "Female", "Gender Diverse"
  "country" : "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  "birthCountry" : "UK" // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
};

SahhaFlutter.postDemographic(demographic)
  .then((success) => {
    debugPrint(success.toString())
  })
  .catchError((error, stackTrace) => {
    debugPrint(error.toString())
  });
const demographic = {
  age: 35, // number
  gender: "Female", // string, "Male", "Female", "Gender Diverse",
  country: "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry: "UK", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthDate: "1990-05-20" // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}

Sahha.postDemographic(demographic, (error: string, success: boolean) => {
  if error {
    console.error(`Error: $ {error}`);
  } else if success {
    console.log(`Success: $ {success}`);
  }
});
const demographic: SahhaDemographic = {
  age: 35, // number
  gender: "Female", // string, "Male", "Female", "Gender Diverse",
  country: "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry: "UK", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthDate: "1990-05-20", // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
};

Sahha.postDemographic({ demographic: demographic })
  .then((data) => {
    console.log(`Success: ${data.success}`);
  })
  .catch((error: Error) => {
    console.error(error);
  });


GET

Sahha.getDemographic() { error, demographic in
    if let error = error {
        print(error)
    }
    if let demographic = demographic {
        print(demographic)
    }
}
Sahha.getDemographic() { error, demographic ->
    if (error != null) {
        println(error)
    } else if (demographic != null) {
        println(demographic)
    }
}
var demographic = {
  "age" : 35, // int
  "gender" : "Female", // string, "Male", "Female", "Gender Diverse"
  "country" : "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  "birthCountry" : "UK" // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
};

SahhaFlutter.getDemographic()
  .then((value) => {
    debugPrint(value)
  })
  .catchError((error, stackTrace) => {
    debugPrint(error.toString())
  });
const demographic = {
  age: 35, // number
  gender: "Female", // string, "Male", "Female", "Gender Diverse",
  country: "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry: "UK", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthDate: "1990-05-20" // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}

Sahha.getDemographic((error: string, value: string) => {
  if error {
    console.error(`Error: $ {error}`);
  } else if value {
    console.log(`Value: $ {value}`);
  }
});
const demographic: SahhaDemographic = {
  age: 35, // number
  gender: "Female", // string, "Male", "Female", "Gender Diverse",
  country: "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry: "UK", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthDate: "1990-05-20", // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
};

Sahha.getDemographic()
  .then((data) => {
    console.log(data.value);
  })
  .catch((error: Error) => {
    console.error(error);
  });

What's next?