PowerShell でQoo10 Data データをCSV に落としてみた

標準PowerShell cmdlets を使ってQoo10 テーブルにアクセス。

CData Cmdlets Module for Qoo10 は、直感的なQoo10 データ連携を提供する標準cmdlet です。 本記事では、Qoo10 Cmdlets を使ったサンプルを提供します。

Creating a Connection to Your Qoo10 Data

Qoo10 に接続するには、ApiKey、Password、およびUser が必要です。

Qoo10 へのアクセスの設定

  • API Key を取得するためには、Qoo10 の営業担当者に依頼する必要があります。
  • Qoo10 営業担当社へ依頼すると後日、API Key が送られてきます。

Qoo10 アカウントの認証


  • ApiKey:Qoo10 営業担当者から受け取ったAPI Key を設定。
  • User: にログインするためのユーザーID を設定。
  • Password: にログインするためのパスワードを設定。

$conn = Connect-Qoo10  -User "$User" -Password "$Password" -ApiKey "$ApiKey"

Selecting Data

Follow the steps below to retrieve data from the GoodsDetail table and pipe the result into to a CSV file:

Select-Qoo10 -Connection $conn -Table GoodsDetail | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myGoodsDetailData.csv -NoTypeInformation

You will notice that we piped the results from Select-Qoo10 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" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.

Deleting Data

The following line deletes any records that match the criteria:

Select-Qoo10 -Connection $conn -Table GoodsDetail -Where "ItemQty = 12" | Remove-Qoo10

Inserting and Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Qoo10, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyGoodsDetailUpdates.csv | %{
  $record = Select-Qoo10 -Connection $Qoo10 -Table GoodsDetail -Where ("Id = `'"+$_.Id+"`'")
    Update-Qoo10 -Connection $qoo10 -Table GoodsDetail -Columns ("ItemNo","ItemTitle") -Values ($_.ItemNo, $_.ItemTitle) -Where ("Id = `'"+$_.Id+"`'")
    Add-Qoo10 -Connection $qoo10 -Table GoodsDetail -Columns ("ItemNo","ItemTitle") -Values ($_.ItemNo, $_.ItemTitle)

As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!