Cmdlets for SAP SuccessFactors

Build 20.0.7654

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our SAPSuccessFactors Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module SAPSuccessFactorsCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module SAPSuccessFactorsCmdlets;

You can then use the Connect-SAPSuccessFactors cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-SAPSuccessFactors -User "username" -Password "password" -CompanyId "CompanyId" -Url "https://api4.successfactors.com"

The CData Cmdlets PowerShell Module for SAP SuccessFactors communicates to SAP SuccessFactors over the OData API. By default, it is enabled. However, if you need to provide additional permissions, please follow the steps from SAP laid out in their support here.

Connecting to SAPSuccessFactors

You can authenticate to SAP SuccessFactors using Basic authentication or OAuth with SAML assertion.

Basic Authentication

You must provide values for the following properties to successfully authenticate to SAP SuccessFactors. Note that the provider will reuse the session opened by SAP SuccessFactors 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 SuccessFactors will be used for authentication.

  • Url, set this to the url of the server hosting Success Factors. Some of the servers are listed here.
  • 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.

  • OAuthGrantType, set this to CLIENT if you are working with an LMS (Learning Micro Services) in order to authenticate to the service. For all the other OData services use SAML. Default value for this property is SAML. Note that this property is only available for OAuth authentication.
  • Url, set this to the url of the server hosting Success Factors. Some of the servers are listed here. In case of connecting to a LMS (Learning Micro Service) the full URL should be specified including the service name.
  • 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.

Retrieving Data

The Select-SAPSuccessFactors cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-SAPSuccessFactors -Connection $conn -Table "SampleTable_1" -Columns @("Id, Column1") -Where "Column2='Bob'"
The Invoke-SAPSuccessFactors cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-SAPSuccessFactors -Connection $conn -Table SampleTable_1 -Where "Column2 = 'Bob'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\mySampleTable_1Data.csv -NoTypeInformation

You will notice that we piped the results from Select-SAPSuccessFactors into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

 
PS C:\> $conn  = Connect-SAPSuccessFactors -User "username" -Password "password" -CompanyId "CompanyId" -Url "https://api4.successfactors.com"
PS C:\> $row = Select-SAPSuccessFactors -Connection $conn -Table "SampleTable_1" -Columns (Id, Column1) -Where "Column2 = 'Bob'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "SampleTable_1",
  "Columns":  [

  ],
  "Id":  "MyId",
  "Column1":  "MyColumn1"
} 

Deleting Data

The following line deletes any records that match the criteria:

Select-SAPSuccessFactors -Connection $conn -Table SampleTable_1 -Where "Column2 = 'Bob'" | Remove-SAPSuccessFactors

Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into SAP SuccessFactors, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MySampleTable_1Updates.csv | %{
  $record = Select-SAPSuccessFactors -Connection $conn -Table SampleTable_1 -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-SAPSuccessFactors -Connection $conn -Table SampleTable_1 -Columns @("Id","Column1") -Values @($_.Id, $_.Column1) -Where "Id  = `'$_.Id`'"
  }else{
    Add-SAPSuccessFactors -Connection $conn -Table SampleTable_1 -Columns @("Id","Column1") -Values @($_.Id, $_.Column1)
  }
}

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7654