![]() |
VOOZH | about |
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.
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:
If you are connecting to the Supplier Data API or the Contract API, additionally set the following:
If you're connecting to the Supplier API, set ProjectId to the Id of the sourcing project you want to retrieve data from.
After setting connection properties, you need to configure OAuth connectivity to authenticate.
For more information on creating an OAuth application, refer to the Help documentation.
After setting the following, you are ready to connect:
When you connect, the provider automatically completes the OAuth process:
Install the module:
Install-Module SAPAribaSourceCmdlets
Connect:
$saparibasource = Connect-SAPAribaSource -API "$API" -APIKey "$APIKey" -Environment "$Environment" -Realm "$Realm" -AuthScheme "$AuthScheme" -InitiateOAuth "$InitiateOAuth"
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'}
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")
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()
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-SAPAribaSource -Connection $SAPAribaSource -Columns @('SMVendorID','Category') -Values @('MySMVendorID', 'MyCategory') -Table Vendors -Id "MyId"
$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()
Add-SAPAribaSource -Connection $SAPAribaSource -Table Vendors -Columns @("SMVendorID", "Category") -Values @("MySMVendorID", "MyCategory")
$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()
Remove-SAPAribaSource -Connection $SAPAribaSource -Table "Vendors" -Id "MyId"
$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()
CodeProject
Download a free trial of the SAP Ariba Source Data Provider to get started:
Download NowLearn more:
👁 SAP Ariba Source IconRapidly create and deploy powerful .NET applications that integrate with SAP Ariba Source.