{ "kind": "open-flow-workflow", "version": 1, "name": "Save Taiwan Sheep Prices to Google Sheets", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_3c8ae99715c58de4": { "name": "Start manually", "kind": "start", "inputDefs": [] }, "n_3bf17ab47020ad2b": { "inputs": { "startDate": { "kind": "value", "value": "2024/12/01" }, "endDate": { "kind": "value", "value": "2024/12/31" }, "market": { "kind": "value", "value": "" } }, "name": "Choose the dates and market", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "startDate" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endDate" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "market" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "market" } ], "name": "Choose the dates and market", "moduleId": "n_8f9bf9d32d47c0c5", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_b3fe898d74bb5ac8": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3bf17ab47020ad2b", "output": "url" } ] } }, "name": "Read sheep quotations", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Read sheep quotations", "executor": { "method": "GET", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "none", "authentication": { "type": "none" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_8f4799f6a8bd4d60": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b3fe898d74bb5ac8", "output": "body" } ] }, "market": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3bf17ab47020ad2b", "output": "market" } ] } }, "name": "Prepare quotation rows", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "market" } ], "outputs": [ { "jsonSchema": { "type": "array", "items": { "type": "array", "items": { "anyOf": [ { "type": "string", "description": "A union variant." }, { "type": "number", "description": "A union variant." }, { "type": "boolean", "description": "A union variant." }, { "const": null, "description": "A union variant." } ], "description": "The cell value schema." }, "description": "An array item." }, "description": "The data to append." }, "nullable": false, "handle": "values" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "hasRows" } ], "name": "Prepare quotation rows", "moduleId": "n_ef1f19d143b5ceee", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_eee6b5f24ef15068": { "inputs": {}, "name": "Any quotations?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "yes", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_8f4799f6a8bd4d60", "output": "hasRows" } }, "operator": "isTrue" } ] } ] } ] }, "n_11262a7cc1d40de9": { "inputs": { "spreadsheetId": { "kind": "value", "value": "YOUR_SPREADSHEET_ID" }, "range": { "kind": "value", "value": "'Sheet1'!A:L" }, "values": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_8f4799f6a8bd4d60", "output": "values" } ] }, "majorDimension": { "kind": "value", "value": "ROWS" }, "valueInputOption": { "kind": "value", "value": "RAW" } }, "name": "Append the quotations", "kind": "task", "task": { "inputs": [ { "description": "The spreadsheet ID.", "jsonSchema": { "type": "string", "minLength": 1, "description": "The spreadsheet ID." }, "nullable": true, "handle": "spreadsheetId", "value": null }, { "description": "The A1 notation of the range to append values after.", "jsonSchema": { "type": "string", "minLength": 1, "description": "The A1 notation of the range to append values after." }, "nullable": false, "handle": "range" }, { "description": "The data to append.", "jsonSchema": { "type": "array", "items": { "type": "array", "items": { "anyOf": [ { "type": "string", "description": "A union variant." }, { "type": "number", "description": "A union variant." }, { "type": "boolean", "description": "A union variant." }, { "const": null, "description": "A union variant." } ], "description": "The cell value schema." }, "description": "An array item." }, "description": "The data to append." }, "nullable": false, "handle": "values" }, { "description": "The major dimension of the values array.", "jsonSchema": { "type": "string", "enum": [ "ROWS", "COLUMNS" ], "description": "The major dimension of the values array." }, "nullable": true, "handle": "majorDimension", "value": null }, { "description": "How the data should be inserted.", "jsonSchema": { "type": "string", "enum": [ "OVERWRITE", "INSERT_ROWS" ], "description": "How the data should be inserted." }, "nullable": true, "handle": "insertDataOption", "value": null }, { "description": "How the input data should be interpreted.", "jsonSchema": { "type": "string", "enum": [ "RAW", "USER_ENTERED" ], "description": "How the input data should be interpreted." }, "nullable": true, "handle": "valueInputOption", "value": null }, { "description": "Whether to include the appended values in the response.", "jsonSchema": { "type": "boolean", "description": "Whether to include the appended values in the response." }, "nullable": true, "handle": "includeValuesInResponse", "value": null }, { "description": "How values in the response should be rendered.", "jsonSchema": { "type": "string", "enum": [ "FORMATTED_VALUE", "UNFORMATTED_VALUE", "FORMULA" ], "description": "How values in the response should be rendered." }, "nullable": true, "handle": "responseValueRenderOption", "value": null }, { "description": "How dates in the response should be rendered.", "jsonSchema": { "type": "string", "enum": [ "SERIAL_NUMBER", "FORMATTED_STRING" ], "description": "How dates in the response should be rendered." }, "nullable": true, "handle": "responseDateTimeRenderOption", "value": null } ], "outputs": [ { "description": "The unique ID of the spreadsheet.", "jsonSchema": { "type": "string", "description": "The unique ID of the spreadsheet." }, "nullable": false, "handle": "spreadsheetId" }, { "description": "The A1 notation of the range that was updated.", "jsonSchema": { "type": "string", "description": "The A1 notation of the range that was updated." }, "nullable": false, "handle": "updatedRange" }, { "description": "The number of rows that were updated.", "jsonSchema": { "type": "integer", "description": "The number of rows that were updated." }, "nullable": false, "handle": "updatedRows" }, { "description": "The number of columns that were updated.", "jsonSchema": { "type": "integer", "description": "The number of columns that were updated." }, "nullable": false, "handle": "updatedColumns" }, { "description": "The number of cells that were updated.", "jsonSchema": { "type": "integer", "description": "The number of cells that were updated." }, "nullable": false, "handle": "updatedCells" }, { "description": "The values of the cells after the update.", "jsonSchema": { "type": "object", "properties": { "range": { "type": "string", "description": "The A1 notation of the range." }, "majorDimension": { "type": "string", "description": "The major dimension of the values (ROWS or COLUMNS)." }, "values": { "type": "array", "items": { "type": "array", "items": { "anyOf": [ { "type": "string", "description": "A union variant." }, { "type": "number", "description": "A union variant." }, { "type": "boolean", "description": "A union variant." }, { "const": null, "description": "A union variant." } ], "description": "The cell value schema." }, "description": "An array item." }, "description": "The data values in the range." } }, "required": [ "range", "majorDimension", "values" ], "additionalProperties": false, "description": "The values of the cells after the update." }, "nullable": true, "handle": "updatedData" }, { "description": "The A1 notation of the table range that data was appended to.", "jsonSchema": { "type": "string", "description": "The A1 notation of the table range that data was appended to." }, "nullable": false, "handle": "tableRange" } ], "name": "Append the quotations", "executor": { "kind": "connector", "action": "googlesheets.spreadsheets_values_append" } } }, "n_e95cb59f0f192e31": { "name": "Finished", "kind": "outputs", "outputDefs": [], "outputMappings": {} } }, "edges": [ { "source": "n_3c8ae99715c58de4", "target": "n_3bf17ab47020ad2b" }, { "source": "n_3bf17ab47020ad2b", "target": "n_b3fe898d74bb5ac8" }, { "source": "n_b3fe898d74bb5ac8", "target": "n_8f4799f6a8bd4d60" }, { "source": "n_8f4799f6a8bd4d60", "target": "n_eee6b5f24ef15068" }, { "source": "n_eee6b5f24ef15068", "target": "n_11262a7cc1d40de9", "sourceHandle": "yes" }, { "source": "n_11262a7cc1d40de9", "target": "n_e95cb59f0f192e31" }, { "source": "n_eee6b5f24ef15068", "target": "n_e95cb59f0f192e31", "sourceHandle": "otherwise" } ] } }, "modules": { "n_8f9bf9d32d47c0c5": { "name": "Choose the dates and market", "imports": [], "source": "export default function query({startDate,endDate,market}){const d=/^\\d{4}\\/\\d{2}\\/\\d{2}$/;if(!d.test(startDate)||!d.test(endDate)||startDate>endDate)throw Error('Enter dates as YYYY/MM/DD, start no later than end');if(typeof market!=='string')throw Error('Invalid market');return{url:'https://data.moa.gov.tw/api/v1/SheepQuotation/?Start_time='+encodeURIComponent(startDate)+'&End_time='+encodeURIComponent(endDate),market}}\n" }, "n_ef1f19d143b5ceee": { "name": "Prepare quotation rows", "imports": [], "source": "export default function rows({body,market}){if(!body||body.RS!=='OK'||!Array.isArray(body.Data)||body.Next!==false)throw Error('Sheep quotation response incomplete or invalid');const fields=['transDate','marketID','shortName','name','productID','productName','productTypeName','quantity','avgWeight','avgPrice','highestPrice','Record_ID'];const values=body.Data.filter(x=>!market||x.shortName===market).map(x=>{if(!x||typeof x!=='object')throw Error('Invalid quotation');return fields.map(f=>{if(typeof x[f]!=='string'&&typeof x[f]!=='number')throw Error('Missing quotation field: '+f);return x[f]})});return {values,hasRows:values.length>0}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }