Automate SAP SuccessFactors Integration Tasks from PowerShell
The CData ADO.NET Provider for SAP SuccessFactors is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SAP SuccessFactors.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for SAP SuccessFactors; this tutorial shows how to use the Provider to create, retrieve, update, and delete SAP SuccessFactors data.
Once you have acquired the necessary connection properties, accessing SAP SuccessFactors data in PowerShell can be enabled in three steps.
You can authenticate to SAP Success Factors using Basic authentication or OAuth with SAML assertion.
Basic Authentication
You must provide values for the following properties to successfully authenticate to SAP Success Factors. Note that the provider will reuse the session opened by SAP Success Factors using cookies. Which means that your credentials will be used only on the first request to open the session. After that, cookies returned from SAP Success Factors will be used for authentication.
- Url: set this to the URL of the server hosting Success Factors. Some of the servers are listed in the SAP support documentation (external link).
- User: set this to the username of your account.
- Password: set this to the password of your account.
- CompanyId: set this to the unique identifier of your company.
OAuth Authentication
You must provide values for the following properties, which will be used to get the access token.
- Url: set this to the URL of the server hosting Success Factors. Some of the servers are listed in the SAP support documentation (external link).
- User: set this to the username of your account.
- CompanyId: set this to the unique identifier of your company.
- OAuthClientId: set this to the API Key that was generated in API Center.
- OAuthClientSecret: the X.509 private key used to sign SAML assertion. The private key can be found in the certificate you downloaded in Registering your OAuth Client Application.
- InitiateOAuth: set this to GETANDREFRESH.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP SuccessFactors\lib\System.Data.CData.SAPSuccessFactors.dll") -
Connect to SAP SuccessFactors:
$conn= New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsConnection("User=username;Password=password;CompanyId=CompanyId;Url=https://api4.successfactors.com;") $conn.Open() -
Instantiate the SAPSuccessFactorsDataAdapter, execute an SQL query, and output the results:
$sql="SELECT address1, zipCode from ExtAddressInfo" $da= New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.address1 $_.zipcode }
Update SAP SuccessFactors Data
$cmd = New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsCommand("UPDATE ExtAddressInfo SET city='Springfield' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert SAP SuccessFactors Data
$cmd = New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsCommand("INSERT INTO ExtAddressInfo (city) VALUES (@mycity)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsParameter("@mycity","Springfield")))
$cmd.ExecuteNonQuery()
Delete SAP SuccessFactors Data
$cmd = New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsCommand("DELETE FROM ExtAddressInfo WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPSuccessFactors.SAPSuccessFactorsParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject