Automate PayPal Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

PayPal ADO.NET Provider

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



Are you looking for a quick and easy way to access PayPal data from PowerShell? We show how to use the Cmdlets for PayPal and the CData ADO.NET Provider for PayPal to connect to PayPal data and synchronize, automate, download, 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.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the PayPal API, 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.

After obtaining the needed connection properties, accessing PayPal data in PowerShell consists of three basic 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 }