Ready to get started?

Connect to live data from Harvest with the API Driver

Connect to Harvest

Automate Harvest Integration Tasks from PowerShell



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

The CData API Driver for ADO.NET is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Harvest.

ADO.NET Provider

The ADO.NET Provider provides a SQL interface for Harvest; this tutorial shows how to use the Provider to retrieve Harvest data.

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

Start by setting the Profile connection property to the location of the Harvest Profile on disk (e.g. C:\profiles\Harvest.apip). Next, set the ProfileSettings connection property to the connection string for Harvest (see below).

Harvest API Profile Settings

To authenticate to Harvest, you can use either Token authentication or the OAuth standard. Use Basic authentication to connect to your own data. Use OAuth to allow other users to connect to their data.

Using Token Authentication

To use Token Authentication, set the APIKey to your Harvest Personal Access Token in the ProfileSettings connection property. In addition to APIKey, set your AccountId in ProfileSettings to connect.

Using OAuth Authentication

First, register an OAuth2 application with Harvest. The application can be created from the "Developers" section of Harvest ID.

After setting the following connection properties, you are ready to connect:

  • ProfileSettings: Set your AccountId in ProfileSettings.
  • AuthScheme: Set this to OAuth.
  • OAuthClientId: Set this to the client ID that you specified in your app settings.
  • OAuthClientSecret: Set this to the client secret that you specified in your app settings.
  • CallbackURL: Set this to the Redirect URI that you specified in your app settings.
  • InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to manage how the driver obtains and refreshes the OAuthAccessToken.

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.API.APIConnection("Profile=C:\profiles\Harvest.apip;ProfileSettings='APIKey=my_personal_key;AccountId=_your_account_id';") $conn.Open()
  3. Instantiate the APIDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, ClientName from Invoices" $da= New-Object System.Data.CData.API.APIDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.clientname }