Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate Xero WorkflowMax Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Xero WorkflowMax data from PowerShell? This article demonstrates how to utilize the Xero WorkflowMax Cmdlets for tasks like connecting to Xero WorkflowMax data, automating operations, downloading data, and more.
The CData Cmdlets for Xero WorkflowMax 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 Xero WorkflowMax.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to Xero WorkflowMax, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Xero WorkflowMax data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Xero WorkflowMax. To access Xero WorkflowMax data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Xero WorkflowMax.
Once you have acquired the necessary connection properties, accessing Xero WorkflowMax data in PowerShell can be enabled in three steps.
To connect to the WorkflowMax API, obtain an APIKey and AccountKey from Xero. This can only be done by contacting Xero support (https://www.workflowmax.com/contact-us).
After obtaining an API Key and Account Key, set the values in the APIKey and AccountKey connection properties. Once these are set, you are ready to connect.
PowerShell
-
Install the module:
Install-Module XeroWorkflowMaxCmdlets
-
Connect:
$xeroworkflowmax = Connect-XeroWorkflowMax -APIKey "$APIKey" -AccountKey "$AccountKey"
-
Search for and retrieve data:
$name = "Cynthia" $clients = Select-XeroWorkflowMax -Connection $xeroworkflowmax -Table "Clients" -Where "Name = `'$Name`'" $clients
You can also use the Invoke-XeroWorkflowMax cmdlet to execute SQL commands:
$clients = Invoke-XeroWorkflowMax -Connection $xeroworkflowmax -Query 'SELECT * FROM Clients WHERE Name = @Name' -Params @{'@Name'='Cynthia'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Xero WorkflowMax\lib\System.Data.CData.XeroWorkflowMax.dll")
-
Connect to Xero WorkflowMax:
$conn= New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxConnection("APIKey=myApiKey;AccountKey=myAccountKey;") $conn.Open()
-
Instantiate the XeroWorkflowMaxDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Name from Clients" $da= New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.name }
Update Xero WorkflowMax Data
PowerShell
Update-XeroWorkflowMax -Connection $XeroWorkflowMax -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Clients -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxCommand("UPDATE Clients SET Name='Cynthia' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Xero WorkflowMax Data
PowerShell
Add-XeroWorkflowMax -Connection $XeroWorkflowMax -Table Clients -Columns @("Id", "Name") -Values @("MyId", "MyName")
ADO.NET
$cmd = New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxCommand("INSERT INTO Clients (Name) VALUES (@myName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxParameter("@myName","Cynthia")))
$cmd.ExecuteNonQuery()
Delete Xero WorkflowMax Data
PowerShell
Remove-XeroWorkflowMax -Connection $XeroWorkflowMax -Table "Clients" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxCommand("DELETE FROM Clients WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.XeroWorkflowMax.XeroWorkflowMaxParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject