![]() |
VOOZH | about |
The CData Cmdlets for Zuora offer live access to Zuora data from within PowerShell. Using PowerShell scripts, you can easily automate regular tasks like data replication. This article will walk through using the CData Cmdlets for Zuora and the CData Cmdlets for MySQL in PowerShell to replicate Zuora data to a MySQL database.
After obtaining the needed connection properties, accessing Zuora data in PowerShell and preparing for replication consists of four basic steps.
Zuora uses the OAuth standard to authenticate users. See the online Help documentation for a full OAuth authentication guide.
In order to create a valid connection with the provider you need to choose one of the Tenant values (USProduction by default) which matches your account configuration. The following is a list with the available options:
Two Zuora services are available: Data Query and AQuA API. By default ZuoraService is set to AQuADataExport.
The Data Query feature enables you to export data from your Zuora tenant by performing asynchronous, read-only SQL queries. We recommend to use this service for quick lightweight SQL queries.
LimitationsAQuA API export is designed to export all the records for all the objects ( tables ). AQuA query jobs have the following limitations:
LimitationsInstall the module:
Install-Module ZuoraCmdlets
Connect to Zuora:
$zuora = Connect-Zuora -OAuthClientID $OAuthClientID -OAuthClientSecret $OAuthClientSecret -Tenant $Tenant -ZuoraService $ZuoraService -InitiateOAuth $InitiateOAuth
Retrieve the data from a specific resource:
$data = Select-Zuora -Connection $zuora -Table "Invoices"
You can also use the Invoke-Zuora cmdlet to execute pure SQL-92 statements:
$data = Invoke-Zuora -Connection $zuora -Query 'SELECT * FROM Invoices WHERE BillingState = @BillingState' -Params @{'@BillingState'='CA'}
Save a list of the column names from the returned data.
$columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name
With the data and column names collected, you are ready to replicate the data into a MySQL database.
Install the module:
Install-Module MySQLCmdlets
Connect to MySQL, using the server address and port of the MySQL server, valid user credentials, and a specific database with the table in which the data will be replicated:
$mysql = Connect-MySQL -User $User -Password $Password -Database $Database -Server $Server -Port $Port
Loop through the Zuora data, store the values, and use the Add-MySQL cmdlet to insert the data into the MySQL database, one row at a time. In this example, the table will need to have the same name as the Zuora resource (Invoices) and to exist in the database.
$data | % {
$row = $_
$values = @()
$columns | % {
$col = $_
$values += $row.$($col)
}
Add-MySQL -Connection $mysql -Table "Invoices" -Columns $columns -Values $values
}
You have now replicated your Zuora data to a MySQL database. This gives you freedom to work with Zuora data in the same way that you work with other MySQL tables, whether that is performing analytics, building reports, or other business functions.
Once you have connected to Zuora and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:
Select-Zuora -Connection $zuora -Table "Invoices" | % {
$row = $_
$values = @()
$columns | % {
$col = $_
$values += $row.$($col)
}
Add-MySQL -Connection $mysql -Table "Invoices" -Columns $columns -Values $values
}
If you wish to replicate the Zuora data to another database using another PowerShell module, you will want to exclude the Columns, Connection, and Table columns from the data returned by the Select-Zuora cmdlet since those columns are used to help pipe data from one CData cmdlet to another:
$columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name | ? {$_ -NotIn @('Columns','Connection','Table')}
Download a free trial of the Zuora Cmdlets to get started:
Download NowLearn more:
👁 Zuora IconAn easy-to-use set of PowerShell Cmdlets offering real-time access to Zuora. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.