> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# REST API データアクセス

> DataFile メソッドと Bearer トークン認証を使用して、データアクセス REST API 経由で ABBYY FlexiCapture のレポートアーカイブを取得する方法を、サンプル付きで説明します。

REST API には、レポートデータを取得するための次のメソッドが用意されています。

* [DataFile メソッド](/ja/flexi-capture/reporting-service/reporting-data-file)
* [DataFile/GetFileList メソッド](/ja/flexi-capture/reporting-service/reporting-data-file-get-file-list)
* [DataFile/CreateFile メソッド](/ja/flexi-capture/reporting-service/reporting-data-file-create-file)

<Info>
  各リクエストは、ABBYY FlexiCapture アプリケーションサーバー から取得した Bearer トークンで[認証](/ja/flexi-capture/reporting-service/reporting-data-access-authentication)する必要があります。そのテナントのデータにアクセスできるのは、そのテナントの Administrator または Monitoring Operator のみです。
</Info>

API の説明を表示するには、ABBYY FlexiCapture Reporting service data access がインストールされている任意のマシンで `http://localhost:8002` を開きます。

<div id="example-script">
  ## スクリプトの例
</div>

以下の PowerShell スクリプトは、ABBYY FlexiCapture アカウントで認証し、指定したテナントと期間のレポート統計アーカイブをダウンロードします。

```powershell theme={null}
# 指定されたテナントのレポート統計アーカイブをダウンロードします
function GetDataFile {
    Param (
        [Parameter(Mandatory=$true)][String]$AppServer,
        [Parameter(Mandatory=$true)][AllowEmptyString()][string]$TenantName,
        [Parameter(Mandatory=$true)][string]$User,
        [Parameter(Mandatory=$true)][string]$Password,
        [Parameter(Mandatory=$true)][Int]$Year,
        [Parameter(Mandatory=$true)][Int]$Month,
        [Parameter(Mandatory=$true)][string]$DownloadPath,
        [Parameter(Mandatory=$true)][string]$ReportingServiseUri
    )
    # 関数パラメーターで渡されたテナント名とアプリケーションサーバーアドレスを使用します
    $URI = "https://$AppServer/Flexicapture12/Server/FCAuth/API/wsdl?Tenant=$TenantName"
    # 指定されたユーザー名とパスワードで PSCredential オブジェクトを作成します
    $creds = New-Object System.Management.Automation.PSCredential -ArgumentList @($user,(ConvertTo-SecureString -String $password -AsPlainText -Force))
    # これらの資格情報で認証するプロキシ Web サービスを作成します
    $proxy = New-WebServiceProxy -Uri $URI -Credential $creds
    $proxy.Url = "https://$AppServer/flexicapture12/Server/FCAuth/API/Soap?Tenant=$TenantName"
    $proxy.Credentials = $creds
    # FlexiCapture API にトークンを要求します
    $ticket = $proxy.GetCurrentUserAuthTicket()
    $nameFile = $year.ToString() + "-" + $month.ToString()
    # ダウンロードファイルのパスを作成します
    $path = "$DownloadPath\$nameFile.zip"
    # トークンを含む Bearer 認証ヘッダーを持つリクエストを作成し、
    # レポートデータアクセスサービスに送信して指定されたテナントと期間のアーカイブを取得します
    $headers = @{ Authorization = "Bearer " + $ticket}
    Invoke-RestMethod -Uri $ReportingServiseUri"?tenantName=$TenantName&year=$year&month=$month" -Headers $headers -OutFile $path
}
GetDataFile
```
