後処理でのレスポンス変換
この手順は、後処理操作でレスポンスを変換するフローを作成する方法を示しています。
このサンプル・コードでは、Google Sheetsからの値の範囲に対してGET APIコールを使用してフローを実装しています。 convertResult式を使用して、出力を値の配列に変換します。
- Google Sheets APIへのGetコールを使用してフローを追加します。
"flows": { "getRowFlow" :{ "id": "getRowFlow", "description": "getRowFlow", "specVersion": "0.8", "version": "0.1", "start": "startState", "functions": [ { "name": "generalRestFunc", "type": "custom", "operation": "connectivity::rest" } ], "states":[ { "name":"startState", "type":"operation", "actions":[ { "functionRef": { "refName": "generalRestFunc", "arguments": { "uri": "https://shhets-svc.api.com/v4/spreadsheets/{spreadsheetId}/values/{range}", "method": "GET", "parameters": { "spreadsheetId": "${ .configuration.spreadsheetId }", "range": "${ .configuration.sheetId + \"!A1:Z\" + (.input.rowNumber|tostring) }", "majorDimension": "COLUMNS" } } }, "actionDataFilter": { "results": "${ .body.values }", "toStateData": "${ .values }" } } ], "end": true } ] } } - 後処理変換を構成します。
- フローに関数定義を追加します。
- 状態の新しいアクションから定義された関数を参照します。
"functions": [ ... { "name": "convertResult", "type": "expression", "operation": "(if .configuration.rowOperation == \"lastRow\" then (.lastLineNumber-1) else (.input.rowNumber-1) end) as $rowNum | .values | map({key:.[0], value:.[$rowNum]}) | from_entries" } ] ... "states":[ { "name":"startState", "type":"operation", "actions":[ ... { "functionRef": "convertResult", "actionDataFilter": { "toStateData": "${ .output }" } } ] - 有効なフローを実行します。
- アクションが構成されている行番号まで、範囲のGoogle Sheets APIに対してGetコールを実行します。
convertResult式を使用して、出力を値の配列に変換します。
"flows": { "getRowFlow" :{ "id": "getRowFlow", "description": "getRowFlow", "specVersion": "0.8", "version": "0.1", "start": "startState", "functions": [ { "name": "generalRestFunc", "type": "custom", "operation": "connectivity::rest" }, { "name": "convertResult", "type": "expression", "operation": "(if .configuration.rowOperation == \"lastRow\" then (.lastLineNumber-1) else (.input.rowNumber-1) end) as $rowNum | .values | map({key:.[0], value:.[$rowNum]}) | from_entries" } ], "states":[ { "name":"startState", "type":"operation", "actions":[ { "functionRef": { "refName": "generalRestFunc", "arguments": { "uri": "https://shhets-svc.api.com/v4/spreadsheets/{spreadsheetId}/values/{range}", "method": "GET", "parameters": { "spreadsheetId": "${ .configuration.spreadsheetId }", "range": "${ .configuration.sheetId + \"!A1:Z\" + (.input.rowNumber|tostring) }", "majorDimension": "COLUMNS" } } }, "actionDataFilter": { "results": "${ .body.values }", "toStateData": "${ .values }" } }, { "functionRef": "convertResult", "actionDataFilter": { "toStateData": "${ .output }" } } ], "end": true } ] } }