Establishing a Connection
With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our AuthorizeNet Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.
Connecting to Authorize.net
Before you connect, log into your Merchant account and navigate to Account > Settings. Your account Security Settings section displays the LoginID and TransactionKey.
Now set the following to connect:
- LoginID: The API login Id associated with your payment gateway account. (Note: This value is not the same as the login Id that you use to log in to the Merchant Interface.)
- TransactionKey: The transaction key associated with your payment gateway account.
- UseSandbox: Set to false by default, for use with a production account. If you are using a developer test account, set UseSandbox to true.
Creating a Connection Object
You can then use the Connect-AuthNet cmdlet to create a connection object that can be passed to other cmdlets:
$conn = Connect-AuthNet -LoginID 'myLoginID' -TransactionKey 'myTransactionKey'
Retrieving Data
The Select-AuthNet cmdlet provides a native PowerShell interface for retrieving data:
$results = Select-AuthNet -Connection $conn -Table "SettledBatchList" -Columns @("TotalCharge, Product") -Where "IncludeStatistics='True'"
The Invoke-AuthNet cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.
Piping Cmdlet Output
The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:
Select-AuthNet -Connection $conn -Table SettledBatchList -Where "IncludeStatistics = 'True'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\mySettledBatchListData.csv -NoTypeInformation
You will notice that we piped the results from Select-AuthNet into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.
However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:
PS C:\> $conn = Connect-AuthNet -LoginID 'myLoginID' -TransactionKey 'myTransactionKey'
PS C:\> $row = Select-AuthNet -Connection $conn -Table "SettledBatchList" -Columns (TotalCharge, Product) -Where "IncludeStatistics = 'True'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
"Connection": {
},
"Table": "SettledBatchList",
"Columns": [
],
"TotalCharge": "MyTotalCharge",
"Product": "MyProduct"
}