Ready to get started?

Download a free trial of the SAP Ariba Source Data Provider to get started:

 Download Now

Learn more:

SAP Ariba Source Icon SAP Ariba Source ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with SAP Ariba Source.

Automate SAP Ariba Source Integration Tasks from PowerShell



Are you in search of a quick and easy way to access SAP Ariba Source data from PowerShell? This article demonstrates how to utilize the SAP Ariba Source Cmdlets and the CData ADO.NET Provider for SAP Ariba Source for tasks like connecting to SAP Ariba Source data, automating operations, downloading data, and more.

The CData Cmdlets for SAP Ariba Source are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SAP Ariba Source.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to SAP Ariba Source, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete SAP Ariba Source data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SAP Ariba Source. To access SAP Ariba Source data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SAP Ariba Source.

Once you have acquired the necessary connection properties, accessing SAP Ariba Source data in PowerShell can be enabled in three steps.

In order to connect with SAP Ariba Source, set the following:

  • API: Specify which API you would like the provider to retrieve SAP Ariba data from. Select the Supplier, Sourcing Project Management, or Contract API based on your business role (possible values are SupplierDataAPIWithPaginationV4, SourcingProjectManagementAPIV2, or ContractAPIV1).
  • DataCenter: The data center where your account's data is hosted.
  • Realm: The name of the site you want to access.
  • Environment: Indicate whether you are connecting to a test or production environment (possible values are TEST or PRODUCTION).

If you are connecting to the Supplier Data API or the Contract API, additionally set the following:

  • User: Id of the user on whose behalf API calls are invoked.
  • PasswordAdapter: The password associated with the authenticating User.

If you're connecting to the Supplier API, set ProjectId to the Id of the sourcing project you want to retrieve data from.

Authenticating with OAuth

After setting connection properties, you need to configure OAuth connectivity to authenticate.

  • Set AuthScheme to OAuthClient.
  • Register an application with the service to obtain the APIKey, OAuthClientId and OAuthClientSecret.

    For more information on creating an OAuth application, refer to the Help documentation.

Automatic OAuth

After setting the following, you are ready to connect:

    APIKey: The Application key in your app settings. OAuthClientId: The OAuth Client Id in your app settings. OAuthClientSecret: The OAuth Secret in your app settings.

When you connect, the provider automatically completes the OAuth process:

  1. The provider obtains an access token from SAP Ariba and uses it to request data.
  2. The provider refreshes the access token automatically when it expires.
  3. The OAuth values are saved in memory relative to the location specified in OAuthSettingsLocation.

PowerShell

  1. Install the module:

    Install-Module SAPAribaSourceCmdlets
  2. Connect:

    $saparibasource = Connect-SAPAribaSource -API "$API" -APIKey "$APIKey" -Environment "$Environment" -Realm "$Realm" -AuthScheme "$AuthScheme"
  3. Search for and retrieve data:

    $region = "USA" $vendors = Select-SAPAribaSource -Connection $saparibasource -Table "Vendors" -Where "Region = `'$Region`'" $vendors

    You can also use the Invoke-SAPAribaSource cmdlet to execute SQL commands:

    $vendors = Invoke-SAPAribaSource -Connection $saparibasource -Query 'SELECT * FROM Vendors WHERE Region = @Region' -Params @{'@Region'='USA'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP Ariba Source\lib\System.Data.CData.SAPAribaSource.dll")
  2. Connect to SAP Ariba Source:

    $conn= New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceConnection("API=SupplierDataAPIWithPagination-V4;APIKey=wWVLn7WTAXrIRMAzZ6VnuEj7Ekot5jnU;Environment=SANDBOX;Realm=testRealm;AuthScheme=OAuthClient;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the SAPAribaSourceDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT SMVendorID, Category from Vendors" $da= New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.smvendorid $_.category }

Update SAP Ariba Source Data

PowerShell

Update-SAPAribaSource -Connection $SAPAribaSource -Columns @('SMVendorID','Category') -Values @('MySMVendorID', 'MyCategory') -Table Vendors -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceCommand("UPDATE Vendors SET Region='USA' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert SAP Ariba Source Data

PowerShell

Add-SAPAribaSource -Connection $SAPAribaSource -Table Vendors -Columns @("SMVendorID", "Category") -Values @("MySMVendorID", "MyCategory")

ADO.NET

$cmd = New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceCommand("INSERT INTO Vendors (Region) VALUES (@myRegion)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceParameter("@myRegion","USA"))) $cmd.ExecuteNonQuery()

Delete SAP Ariba Source Data

PowerShell

Remove-SAPAribaSource -Connection $SAPAribaSource -Table "Vendors" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceCommand("DELETE FROM Vendors WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SAPAribaSource.SAPAribaSourceParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()