Ready to get started?

Download a free trial of the PayPal Data Provider to get started:

 Download Now

Learn more:

PayPal Icon PayPal ADO.NET Provider

Easy-to-use PayPal client enables .NET-based applications to easily consume PayPal Transactions, Orders, Sales, Invoices, etc.

Automate PayPal Integration Tasks from PowerShell



Are you in search of a quick and easy way to access PayPal data from PowerShell? This article demonstrates how to utilize the PayPal Cmdlets for tasks like connecting to PayPal data, automating operations, downloading data, and more.

The CData Cmdlets for PayPal are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to PayPal.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to PayPal, but also an SQL interface; this tutorial shows how to use both to retrieve PayPal data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for PayPal. To access PayPal data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for PayPal.

Once you have acquired the necessary connection properties, accessing PayPal data in PowerShell can be enabled in three steps.

The provider surfaces tables from two PayPal APIs. The APIs use different authentication methods.

  • The REST API uses the OAuth standard. To authenticate to the REST API, you will need to set the OAuthClientId, OAuthClientSecret, and CallbackURL properties.
  • The Classic API requires Signature API credentials. To authenticate to the Classic API, you will need to obtain an API username, password, and signature.

See the "Getting Started" chapter of the help documentation for a guide to obtaining the necessary API credentials.

To select the API you want to work with, you can set the Schema property to REST or SOAP. By default the SOAP schema will be used.

For testing purposes you can set UseSandbox to true and use sandbox credentials.

PowerShell

  1. Install the module:

    Install-Module PayPalCmdlets
  2. Connect:

    $paypal = Connect-PayPal -Schema "$Schema" -Username "$Username" -Password "$Password" -Signature "$Signature"
  3. Search for and retrieve data:

    $transactionclass = "Received" $transactions = Select-PayPal -Connection $paypal -Table "Transactions" -Where "TransactionClass = `'$TransactionClass`'" $transactions

    You can also use the Invoke-PayPal cmdlet to execute SQL commands:

    $transactions = Invoke-PayPal -Connection $paypal -Query 'SELECT * FROM Transactions WHERE TransactionClass = @TransactionClass' -Params @{'@TransactionClass'='Received'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for PayPal\lib\System.Data.CData.PayPal.dll")
  2. Connect to PayPal:

    $conn= New-Object System.Data.CData.PayPal.PayPalConnection("Schema=SOAP;Username=sandbox-facilitator_api1.test.com;Password=xyz123;Signature=zx2127;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the PayPalDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Date, GrossAmount from Transactions" $da= New-Object System.Data.CData.PayPal.PayPalDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.date $_.grossamount }