# Authパラメータ
$endpoint = "https://preprod01.flexicapture.com"
$tenant = "tenantName"
$user = "FCUserName"
$pass = "password"
$filePath = "c:\temp\report.csv"
# レポートパラメータ
$reportType = 3
$jsonparameters = @"
[
{
"Name": "dateFrom",
"Value": "2022-08-31T21:00:00.000Z"
},
{
"Name": "dateTo",
"Value": "2022-09-01T21:00:00.000Z"
},
{
"Name": "projects",
"Value": [
5,
6,
7,
9,
10,
11,
12,
13,
14,
15,
16,
17,
19,
20,
28,
81,
221
]
},
{
"Name": "aggregateByBatchTypes",
"Value": true
},
{
"Name": "groupByType",
"Value": 1
},
{
"Name": "grouping",
"Value": "ProcessingStageName"
},
{
"Name": "columns",
"Value": [
"ProjectId",
"BatchTypeName",
"ProcessedBatchs",
"ProcessedDocs"
]
}
]
"@
###################################################
clear
$ErrorActionPreference="stop"
# FlexiCapture SOAP APIから認証のためのauthTicketを取得しています
$tenantSuffix=""
$tenantInUrl = ""
if (($tenant -ne $null) -or ($tenant -eq "")) {
$tenantSuffix= "?Tenant="+$tenant
$tenantInUrl = "/$tenant"
}
$URL = $endpoint+'/FlexiCapture12/Server/FCAuth/API/Soap'+$tenantSuffix
$SOAPRequest = @"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<FindUser xmlns="urn:http://www.abbyy.com/FlexiCapture">
<userLogin>$user</userLogin>
</FindUser>
</soap:Body>
</soap:Envelope>
"@
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
'SOAPAction' = '"#FindUser"'
'Content-Type' = 'text/xml; charset=utf-8'
'Authorization' = "$basicAuthValue"
}
$response = Invoke-WebRequest -Uri $URL `
-Headers $Headers `
-Body $SOAPRequest `
-Method 'POST' `
$authTicket = $response.Headers['AuthTicket']
#認証クッキーを作成する
$session = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$cookie = [System.Net.Cookie]::new('FlexiCaptureTmpPrn', "Ticket=$authTicket")
$session.Cookies.Add($endpoint, $cookie)
# API経由でレポートをリクエストして保存する
$uriGet = $endpoint+ "/FlexiCapture12/Monitoring$tenantInUrl/Report/GetCSV?reportType=$reportType&filterParametersJson="
$uriGet += [uri]::EscapeDataString($jsonparameters)
$header = @{
"Accept" = "*/*"
"Accept-Encoding" = "gzip, deflate, br"
}
$response = Invoke-RestMethod -Uri $uriGet -Method 'GET' -Headers $header -WebSession $session -OutFile $filePath