SuccessFactors¶
The SuccessFactors class is the client for the SAP SuccessFactors OData API.
successfactors
¶
SuccessFactors Module to interact with the SuccessFactors API.
See: https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/how-to-initiate-an-oauth-connection-to-successfactors-employee-central/ba-p/13332388 https://help.sap.com/docs/SAP_SUCCESSFACTORS_PLATFORM/d599f15995d348a1b45ba5603e2aba9b/78b1d8aac783455684a7de7a8a5b0c04.html
Classes:
| Name | Description |
|---|---|
SuccessFactors |
Class SuccessFactors is used to retrieve and automate settings in SuccessFactors. |
SuccessFactors
¶
SuccessFactors(
base_url: str,
as_url: str,
client_id: str,
client_secret: str,
username: str = "",
password: str = "",
company_id: str = "",
authorization_url: str = "",
logger: Logger = default_logger,
)
Class SuccessFactors is used to retrieve and automate settings in SuccessFactors.
Initialize the SuccessFactors object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL of the SuccessFactors tenant. |
required |
as_url
|
str
|
The Application Service URL of the SuccessFactors tenant. |
required |
client_id
|
str
|
The SuccessFactors Client ID. |
required |
client_secret
|
str
|
The SuccessFactors Client Secret. |
required |
username
|
str
|
The user name in SuccessFactors. |
''
|
password
|
str
|
The password of the SuccessFactors user. |
''
|
company_id
|
str
|
The SuccessFactors company ID. |
''
|
authorization_url
|
str
|
URL for SuccessFactors login. If not given it will be constructed with default values using base_url. |
''
|
logger
|
Logger
|
The logging object to use for all log messages. Defaults to default_logger. |
default_logger
|
Methods:
| Name | Description |
|---|---|
config |
Return the configuration dictionary. |
credentials |
Return the login credentials. |
idp_data |
Return the IDP data used to request the SAML assertion. |
request_header |
Return the request header used for Application calls. |
do_request |
Execute an HTTP request with retries for transient failures. |
parse_request_response |
Convert the request response (JSON) to a Python dict in a safe way. |
exist_result_item |
Check existence of key / value pair in the response properties of a SuccessFactors API call. |
get_result_value |
Get value of a result property with a given key of a SuccessFactors API call. |
get_saml_assertion |
Get SAML Assertion for SuccessFactors authentication. |
authenticate |
Authenticate at SuccessFactors with client ID and client secret. |
get_country |
Get information for a country / countries. |
get_user |
Get information for a SuccessFactors user account. |
get_user_account |
Get information for a SuccessFactors User Account. |
update_user |
Update user data. E.g. update the user password or email. |
get_employee |
Get a list of employee(s) matching given criteria. |
get_entities_metadata |
Get the schema (metadata) for a list of entities (list can be empty to get it for all). |
get_entity_metadata |
Get the schema (metadata) for an entity. |
update_user_email |
Update user email. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
config
¶
Return the configuration dictionary.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The configuration dictionary. |
credentials
¶
Return the login credentials.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary with login credentials for SuccessFactors. |
idp_data
¶
Return the IDP data used to request the SAML assertion.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary with IDP data for SuccessFactors. |
request_header
¶
Return the request header used for Application calls.
Consists of Bearer access token and Content Type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_type
|
str
|
The content type for the request. Defaults to "application/json". |
'application/json'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The request header values. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
do_request
¶
do_request(
url: str,
method: str = "GET",
headers: dict | None = None,
data: dict | None = None,
json_data: dict | None = None,
timeout: float = REQUEST_TIMEOUT,
show_error: bool = True,
show_warning: bool = False,
warning_message: str = "",
failure_message: str = "",
success_message: str = "",
max_retries: int = REQUEST_MAX_RETRIES,
retry_delay: float = REQUEST_RETRY_DELAY,
retry_status_codes: tuple[
int, ...
] = REQUEST_RETRY_STATUS_CODES,
parse_request_response: bool = True,
) -> dict | Response | None
Execute an HTTP request with retries for transient failures.
Returns parsed JSON by default. Returns the raw response only when
parse_request_response is False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the request to. |
required |
method
|
str
|
The HTTP method (GET, POST, etc.). Defaults to "GET". |
'GET'
|
headers
|
dict | None
|
The request headers. Defaults to None. |
None
|
data
|
dict | None
|
The request payload sent as form data. Defaults to None. |
None
|
json_data
|
dict | None
|
The request payload sent as JSON. Defaults to None. |
None
|
timeout
|
float
|
The timeout for the request in seconds. Defaults to REQUEST_TIMEOUT. |
REQUEST_TIMEOUT
|
show_error
|
bool
|
Whether to log an error if the request fails. If False, a warning is logged only if show_warning is True. Defaults to True. |
True
|
show_warning
|
bool
|
Whether to log a warning if the request fails (used if show_error is False or for timeouts and connection errors). Defaults to False. |
False
|
warning_message
|
str
|
Specific warning message. If not given the failure_message is used. |
''
|
failure_message
|
str
|
Description of the failed action, used in log messages. |
''
|
success_message
|
str
|
Message that is logged if the request succeeds. |
''
|
max_retries
|
int
|
The maximum number of retries. Defaults to REQUEST_MAX_RETRIES. |
REQUEST_MAX_RETRIES
|
retry_delay
|
float
|
The base delay in seconds between retries. The delay is multiplied by the number of the retry. Defaults to REQUEST_RETRY_DELAY. |
REQUEST_RETRY_DELAY
|
retry_status_codes
|
tuple[int, ...]
|
The HTTP status codes that trigger a retry. Defaults to REQUEST_RETRY_STATUS_CODES. |
REQUEST_RETRY_STATUS_CODES
|
parse_request_response
|
bool
|
Whether the response should be parsed as JSON into a dictionary. If False, the raw response is returned. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
dict | Response | None
|
dict | requests.Response | None: The parsed response, or the raw response if parse_request_response is False. None in case of an error. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
parse_request_response
¶
parse_request_response(
response_object: Response,
additional_error_message: str = "",
show_error: bool = True,
) -> dict | None
Convert the request response (JSON) to a Python dict in a safe way.
It also handles exceptions. It first tries to load the response.text via json.loads() that produces a dict output. Only if response.text is not set or is empty it just converts the response_object to a dict using the vars() built-in method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_object
|
Response
|
This is the response object delivered by the request call. |
required |
additional_error_message
|
str
|
Provide a more specific error message in case of an error. |
''
|
show_error
|
bool
|
True: write an error to the log file. False: write a warning to the log file. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: The response information or None in case of an error. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
exist_result_item
¶
Check existence of key / value pair in the response properties of a SuccessFactors API call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
dict
|
REST response from a SuccessFactors API call |
required |
key
|
str
|
The property name (key). |
required |
value
|
str
|
The value to find in the item with the matching key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value was found, False otherwise |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
get_result_value
¶
Get value of a result property with a given key of a SuccessFactors API call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
dict
|
REST response from a SuccessFactors REST Call |
required |
key
|
str
|
The property name (key). |
required |
index
|
int
|
Index to use (1st element has index 0). Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The value for the key, None if not found. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
get_saml_assertion
¶
Get SAML Assertion for SuccessFactors authentication.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The SAML assertion. Also stores the assertion in self._assertion. Returns None in case of an error. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
authenticate
¶
Authenticate at SuccessFactors with client ID and client secret.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
revalidate
|
bool
|
Determine if a re-authentication is enforced (e.g. if session has timed out with 401 error). |
False
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Access token. Also stores access token in self._access_token. None in case of error |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
get_country
¶
Get information for a country / countries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
3 character code for country selection, like "USA" |
''
|
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: Country details |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
get_user
¶
get_user(
user_id: str = "",
field_name: str = "",
field_value: str = "",
field_operation: str = "eq",
max_results: int = 1,
) -> dict | None
Get information for a SuccessFactors user account.
Inactive users are not returned by default. To query inactive users, you can explicitly include the status in a $filter or use a key predicate. If you want to query all users, use query option $filter=status in 't','f','T','F','e','d'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The ID of the user (e.g. 106020). This is NOT the login name. If given, the user is queried by key predicate. |
''
|
field_name
|
str
|
The field name of the filter. |
''
|
field_value
|
str
|
The filter value to compare the field with. |
''
|
field_operation
|
str
|
The operation of the filter. Like "in". Defaults to "eq". |
'eq'
|
max_results
|
int
|
The maximum number of results to return. Default is 1. |
1
|
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: User details |
Example
Return data in the "d" dictionary:
{ '__metadata': { 'uri': "https://apisalesdemo2.successfactors.eu/odata/v2/User('106020')", 'type': 'SFOData.User' }, 'userId': '106020', 'salaryBudgetFinalSalaryPercentage': None, 'dateOfCurrentPosition': '/Date(1388534400000)/', 'matrix1Label': None, 'salary': '79860.0', 'objective': '0.0', 'ssn': None, 'state': 'New South Wales', 'issueComments': None, 'timeZone': 'Australia/Sydney', 'defaultLocale': 'en_US', 'nationality': None, 'salaryBudgetLumpsumPercentage': None, 'sysCostOfSource': None, 'ethnicity': None, 'displayName': 'Mark Burke', 'payGrade': 'GR-06', 'nickname': None, 'email': 'Mark.Burke@bestrunsap.com', 'salaryBudgetExtra2Percentage': None, 'stockBudgetOther1Amount': None, 'raiseProrating': None, 'sysStartingSalary': None, 'finalJobCode': None, 'lumpsum2Target': None, 'stockBudgetOptionAmount': None, 'country': 'Australia', 'lastModifiedDateTime': '/Date(1689005658000+0000)/', 'stockBudgetStockAmount': None, 'sciLastModified': None, 'criticalTalentComments': None, 'homePhone': None, 'veteranSeparated': False, 'stockBudgetOther2Amount': None, 'firstName': 'Mark', 'stockBudgetUnitAmount': None, 'salutation': '10808', 'impactOfLoss': None, 'benchStrength': None, 'sysSource': None, 'futureLeader': None, 'title': 'HR Business Partner', 'meritEffectiveDate': None, 'veteranProtected': False, 'lumpsumTarget': None, 'employeeClass': 'Active', 'hireDate': '/Date(1388534400000)/', 'matrix2Label': None, 'salaryLocal': None, 'citizenship': None, 'reasonForLeaving': None, 'riskOfLoss': None, 'location': 'Sydney (8510-0001)', 'reloComments': None, 'username': 'mburke', 'serviceDate': None, 'reviewFreq': None, 'salaryBudgetTotalRaisePercentage': None, ... }
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
get_user_account
¶
Get information for a SuccessFactors User Account.
Inactive users are not returned by default. To query inactive users, you can explicitly include the status in a $filter or use a key predicate. If you want to query all users, use query option $filter=status in 't','f','T','F','e','d'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
The login name of the user (e.g. "twalker"). |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: User Account details. |
Example
Return data in the "d" dictionary:
{ '__metadata': { 'uri': "https://apisalesdemo2.successfactors.eu/odata/v2/UserAccount('twalker')", 'type': 'SFOData.UserAccount' }, 'username': 'twalker', 'lastModifiedDateTime': '/Date(1692701804000+0000)/', 'accountUuid': '5c7390e0-d9d2-e348-1700-2b02b3a61aa5', 'createdDateTime': '/Date(1420745485000+0000)/', 'timeZone': 'US/Eastern', 'lastInactivationDateTime': None, 'accountIsLocked': 'FALSE', 'accountStatus': 'ACTIVE', 'defaultLocale': 'en_US', 'lastLoginFailedDateTime': None, 'accountId': '90', 'sapGlobalUserId': None, 'personIdExternal': '82094', 'userType': 'employee', 'email': 'twalker@m365x41497014.onmicrosoft.com', 'user': {'__deferred': {...}} }
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
update_user
¶
Update user data. E.g. update the user password or email.
See: https://help.sap.com/docs/SAP_SUCCESSFACTORS_PLATFORM/d599f15995d348a1b45ba5603e2aba9b/47c39724e7654b99a6be2f71fce1c50b.html?locale=en-US
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The ID of the user (e.g. 106020) |
required |
update_data
|
dict
|
The data to update the user with. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: Request response or None if an error occurred. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
get_employee
¶
get_employee(
entity: str = "PerPerson",
field_name: str = "",
field_value: str = "",
field_operation: str = "eq",
max_results: int = 1,
) -> dict | None
Get a list of employee(s) matching given criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
str
|
Entity type to query. Examples are "PerPerson" (default), "PerPersonal", "PerEmail", "PersonKey", ... |
'PerPerson'
|
field_name
|
str
|
Field to search in. E.g. personIdExternal, firstName, lastName, fullName, email, dateOfBirth, gender, nationality, maritalStatus, employeeId. |
''
|
field_value
|
str
|
Value to match in the Field |
''
|
field_operation
|
str
|
The operation to apply for the filter. Default is 'eq' (equal). |
'eq'
|
max_results
|
int
|
The maximum number of results to return. Default is 1. |
1
|
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: Dictionary with the SuccessFactors object data or None in case the request failed. |
Examples:
Example result values for "PerPerson" inside the "d" structure: "results": [ { '__metadata': {...}, 'personIdExternal': '109031', 'lastModifiedDateTime': '/Date(1442346839000+0000)/', 'lastModifiedBy': 'admindlr', 'createdDateTime': '/Date(1442346265000+0000)/', 'dateOfBirth': '/Date(-501206400000)/', 'perPersonUuid': '0378B0E6F41444EBB90345B56D537D3D', 'createdOn': '/Date(1442353465000)/', 'lastModifiedOn': '/Date(1442354039000)/', 'countryOfBirth': 'RUS', 'createdBy': 'admindlr', 'regionOfBirth': None, 'personId': '771', 'personalInfoNav': {...}, 'emergencyContactNav': {...}, 'secondaryAssignmentsNav': {...}, 'personEmpTerminationInfoNav': {...}, 'phoneNav': {...}, 'employmentNav': {...}, ... } ]
Example result values for "PerPersonal" inside the "d" structure: "results": [ { '__metadata': { 'uri': "https://apisalesdemo2.successfactors.eu/odata/v2/PerPersonal(personIdExternal='108729',startDate=datetime'2017-03-13T00:00:00')", 'type': 'SFOData.PerPersonal' }, 'personIdExternal': '108729', 'startDate': '/Date(1489363200000)/', 'lastModifiedDateTime': '/Date(1489442337000+0000)/', 'endDate': '/Date(253402214400000)/', 'createdDateTime': '/Date(1489442337000+0000)/', 'suffix': None, 'attachmentId': None, 'preferredName': 'Hillary', 'lastNameAlt1': None, 'firstName': 'Hillary', 'nationality': 'USA', 'salutation': '30085', 'maritalStatus': '10825', 'lastName': 'Lawson', 'gender': 'F', 'firstNameAlt1': None, 'createdOn': '/Date(1489445937000)/', 'middleNameAlt1': None, 'lastModifiedBy': '82094', 'lastModifiedOn': '/Date(1489445937000)/', 'createdBy': '82094', 'middleName': None, 'nativePreferredLang': '10249', 'localNavAUS': {'__deferred': {...}}, 'localNavBGD': {'__deferred': {...}}, 'localNavHKG': {'__deferred': {...}}, 'localNavMYS': {'__deferred': {...}}, 'localNavAUT': {'__deferred': {...}}, 'localNavLKA': {'__deferred': {...}}, 'localNavPOL': {'__deferred': {...}}, 'localNavCZE': {'__deferred': {...}}, 'localNavTWN': {'__deferred': {...}}, 'localNavARE': {'__deferred': {...}}, 'localNavARG': {'__deferred': {...}}, 'localNavCAN': {'__deferred': {...}}, 'localNavNOR': {'__deferred': {...}}, 'localNavOMN': {'__deferred': {...}}, 'localNavPER': {'__deferred': {...}}, 'localNavSGP': {'__deferred': {...}}, 'localNavVEN': {'__deferred': {...}}, 'localNavZAF': {'__deferred': {...}}, 'localNavCHL': {'__deferred': {...}}, 'localNavCHE': {'__deferred': {...}}, 'localNavDNK': {'__deferred': {...}}, 'localNavGTM': {'__deferred': {...}}, 'localNavNZL': {'__deferred': {...}}, 'salutationNav': {'__deferred': {...}}, 'localNavCHN': {'__deferred': {...}}, 'localNavVNM': {'__deferred': {...}}, 'localNavIDN': {'__deferred': {...}}, 'localNavPRT': {'__deferred': {...}}, 'localNavCOL': {'__deferred': {...}}, 'localNavHUN': {'__deferred': {...}}, 'localNavSWE': {'__deferred': {...}}, 'localNavESP': {'__deferred': {...}}, 'localNavUSA': {'__deferred': {...}}, 'nativePreferredLangNav': {'__deferred': {...}}, 'maritalStatusNav': {'__deferred': {...}}, ...}
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 | |
get_entities_metadata
¶
Get the schema (metadata) for a list of entities (list can be empty to get it for all).
IMPORTANT: A metadata request using $metadata returns an XML serialization of the service, including the entity data model (EDM) and the service operation descriptions. The metadata response supports only application/xml type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list | None
|
A list of entities to deliver metadata for. |
None
|
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: Dictionary with the SuccessFactors object data or None in case the request failed. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
get_entity_metadata
¶
Get the schema (metadata) for an entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
str
|
The entity to deliver metadata for. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: Dictionary with the SuccessFactors object data or None in case the request failed. |
Source code in packages/pyxecm/src/pyxecm_customizer/successfactors.py
update_user_email
¶
Update user email.
See: https://help.sap.com/docs/SAP_SUCCESSFACTORS_PLATFORM/d599f15995d348a1b45ba5603e2aba9b/7b3daeb3d77d491bb401345eede34bb5.html?locale=en-US
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The ID of the user (e.g. 106020). |
required |
email_address
|
str
|
The new email address of user. |
required |
email_type
|
int
|
Type of the email. 8448 = Business. Defaults to 8448. |
8448
|
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: Request response or None if an error occurred. |