![]() |
VOOZH | about |
The CData Cmdlets for Adobe Commerce 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 Adobe Commerce.
The Cmdlets are not only a PowerShell interface to Adobe Commerce, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Adobe Commerce data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Adobe Commerce. To access Adobe Commerce data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Adobe Commerce.
Once you have acquired the necessary connection properties, accessing Adobe Commerce data in PowerShell can be enabled in three steps.
Adobe Commerce uses the OAuth 1 authentication standard. To connect to the Adobe Commerce REST API, obtain values for the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties by registering an app with your Adobe Commerce system. See the "Getting Started" section in the help documentation for a guide to obtaining the OAuth values and connecting.
You will also need to provide the URL to your Adobe Commerce system. The URL depends on whether you are using the Adobe Commerce REST API as a customer or administrator.
Customer: To use Adobe Commerce as a customer, make sure you have created a customer account in the Adobe Commerce homepage. To do so, click Account -> Register. You can then set the URL connection property to the endpoint of your Adobe Commerce system.
Administrator: To access Adobe Commerce as an administrator, set CustomAdminPath instead. This value can be obtained in the Advanced settings in the Admin menu, which can be accessed by selecting System -> Configuration -> Advanced -> Admin -> Admin Base URL.
If the Use Custom Admin Path setting on this page is set to YES, the value is inside the Custom Admin Path text box; otherwise, set the CustomAdminPath connection property to the default value, which is "admin".
Install the module:
Install-Module Adobe CommerceCmdlets
Connect:
$adobe commerce = Connect-Adobe Commerce -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -Url "$Url"
Search for and retrieve data:
$style = "High Tech" $products = Select-Adobe Commerce -Connection $adobe commerce -Table "Products" -Where "Style = `'$Style`'" $products
You can also use the Invoke-Adobe Commerce cmdlet to execute SQL commands:
$products = Invoke-Adobe Commerce -Connection $adobe commerce -Query 'SELECT * FROM Products WHERE Style = @Style' -Params @{'@Style'='High Tech'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Adobe Commerce\lib\System.Data.CData.Adobe Commerce.dll")
Connect to Adobe Commerce:
$conn= New-Object System.Data.CData.Adobe Commerce.Adobe CommerceConnection("OAuthClientId=MyConsumerKey;OAuthClientSecret=MyConsumerSecret;CallbackURL=http://127.0.0.1:33333;Url=https://myAdobe Commercehost.com;")
$conn.Open()
Instantiate the Adobe CommerceDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, Price from Products"
$da= New-Object System.Data.CData.Adobe Commerce.Adobe CommerceDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.name $_.price
}
Update-Adobe Commerce -Connection $Adobe Commerce -Columns @('Name','Price') -Values @('MyName', 'MyPrice') -Table Products -Id "MyEntityId"
$cmd = New-Object System.Data.CData.Adobe Commerce.Adobe CommerceCommand("UPDATE Products SET Style='High Tech' WHERE EntityId = @myEntityId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Adobe Commerce.Adobe CommerceParameter("@myEntityId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Adobe Commerce -Connection $Adobe Commerce -Table Products -Columns @("Name", "Price") -Values @("MyName", "MyPrice")
$cmd = New-Object System.Data.CData.Adobe Commerce.Adobe CommerceCommand("INSERT INTO Products (Style) VALUES (@myStyle)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Adobe Commerce.Adobe CommerceParameter("@myStyle","High Tech")))
$cmd.ExecuteNonQuery()
Remove-Adobe Commerce -Connection $Adobe Commerce -Table "Products" -Id "MyEntityId"
$cmd = New-Object System.Data.CData.Adobe Commerce.Adobe CommerceCommand("DELETE FROM Products WHERE EntityId=@myEntityId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Adobe Commerce.Adobe CommerceParameter("@myEntityId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Adobe Commerce Data Provider to get started:
Download NowLearn more:
👁 Adobe Commerce IconRapidly create and deploy powerful .NET applications that integrate with Adobe Commerce data including Customers, Inventory, Products, Orders, and more!