![]() |
VOOZH | about |
The CData Cmdlets for Shopify 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 Shopify.
The Cmdlets are not only a PowerShell interface to Shopify, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Shopify data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Shopify. To access Shopify data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Shopify.
Once you have acquired the necessary connection properties, accessing Shopify data in PowerShell can be enabled in three steps.
To make use of all the features of the data provider, provide the AppId, Password, and ShopUrl connection properties.
To obtain these values, see the Getting Started section in the help documentation to register the data provider as an application with Shopify.
Install the module:
Install-Module ShopifyCmdlets
Connect:
$shopify = Connect-Shopify -AppId "$AppId" -Password "$Password" -ShopUrl "$ShopUrl"
Search for and retrieve data:
$firstname = "jdoe1234" $customers = Select-Shopify -Connection $shopify -Table "Customers" -Where "FirstName = `'$FirstName`'" $customers
You can also use the Invoke-Shopify cmdlet to execute SQL commands:
$customers = Invoke-Shopify -Connection $shopify -Query 'SELECT * FROM Customers WHERE FirstName = @FirstName' -Params @{'@FirstName'='jdoe1234'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Shopify\lib\System.Data.CData.Shopify.dll")
Connect to Shopify:
$conn= New-Object System.Data.CData.Shopify.ShopifyConnection("AppId=MyAppId;Password=MyPassword;ShopUrl=https://yourshopname.myshopify.com;")
$conn.Open()
Instantiate the ShopifyDataAdapter, execute an SQL query, and output the results:
$sql="SELECT FirstName, Id from Customers"
$da= New-Object System.Data.CData.Shopify.ShopifyDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.firstname $_.id
}
Update-Shopify -Connection $Shopify -Columns @('FirstName','Id') -Values @('MyFirstName', 'MyId') -Table Customers -Id "MyId"
$cmd = New-Object System.Data.CData.Shopify.ShopifyCommand("UPDATE Customers SET FirstName='jdoe1234' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Shopify.ShopifyParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Shopify -Connection $Shopify -Table Customers -Columns @("FirstName", "Id") -Values @("MyFirstName", "MyId")
$cmd = New-Object System.Data.CData.Shopify.ShopifyCommand("INSERT INTO Customers (FirstName) VALUES (@myFirstName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Shopify.ShopifyParameter("@myFirstName","jdoe1234")))
$cmd.ExecuteNonQuery()
Remove-Shopify -Connection $Shopify -Table "Customers" -Id "MyId"
$cmd = New-Object System.Data.CData.Shopify.ShopifyCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Shopify.ShopifyParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Shopify Data Provider to get started:
Download NowLearn more:
👁 Shopify IconRapidly create and deploy powerful .NET applications that integrate with Shopify Ecommerce Software.