{
  "elementsLearnedData": [],
  "elementsTestData": [],
  "flow": {
    "id": "5A824D7D-BFFF-47D3-BD8C-79509E2997AC",
    "name": "Sendcloud: daily returns log with reason alerts"
  },
  "flowVersion": {
    "clientMetadata": {
      "viewport": {
        "x": 169.73284272991532,
        "y": 24.806736545292637,
        "zoom": 0.6355158446528336
      },
      "autoSave": true,
      "descriptions": {
        "flow": "Each morning, adds new Sendcloud returns to a returns log in Google Sheets, counts return reasons over the last 7 days, and posts to Slack when a reason crosses the alert threshold.",
        "initialData": "",
        "initialDataFields": {}
      }
    },
    "description": "Each morning, adds new Sendcloud returns to a returns log in Google Sheets, counts return reasons over the last 7 days, and posts to Slack when a reason crosses the alert threshold.",
    "elements": [
      {
        "clientMetadata": {
          "notes": "Sends messages to Slack channels with optional Block Kit rich layouts. Supports plain text with Slack formatting, or advanced Block Kit JSON for buttons, menus, and interactive elements. Returns the message timestamp and channel ID for later updates or tracking.",
          "elementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "isFirstElement": false,
          "dynamicOptionLabels": {
            "channelId": {}
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Alert the team in Slack Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "legacyElementId": "JS###v1###Slack###sendMessageToChannel",
          "methodName": "sendMessageToChannel",
          "position": {
            "x": 960.2367114260401,
            "y": 771.8189069614784
          }
        },
        "flowElementId": "30BEA7F9-1424-4603-B097-160BA324D257",
        "groupId": null,
        "id": "E9F9208E-4FB0-4F8C-926F-34F60035D54A",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "channelId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ""
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "messageText",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Reason counts",
                    "subPathSegments": [
                      {
                        "key": "message",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "5B242432-13AB-40B8-A95B-5CBBF2252678"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "threadId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sendAsBot",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "botName",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "botIcon",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "replyBroadcast",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "imageURL",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "blocks",
              "type": "COMPLEX_LIST",
              "value": []
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "sendMessageToChannel",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Alert message",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "slack",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Alert the team in Slack",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Pick out new returns Result"
          },
          "position": {
            "x": 690,
            "y": 110
          }
        },
        "flowElementId": "F7CA9BC9-9C3B-49D0-9220-075A9EF766E0",
        "groupId": null,
        "id": "039E8EBD-F56C-451D-88A0-5C9A6B3CFF3B",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "returnsList",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Sendcloud returns",
                    "subPathSegments": [
                      {
                        "key": "returns",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "580D67B2-F735-422C-9801-F0EA7E623195"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "resultsList",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Sendcloud returns",
                    "subPathSegments": [
                      {
                        "key": "results",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "580D67B2-F735-422C-9801-F0EA7E623195"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "logRows",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Returns log",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "9DC1AEFF-3D7E-4D92-8101-DA89A72D4DE6"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const list = Array.isArray(returnsList) ? returnsList : (Array.isArray(resultsList) ? resultsList : []);\nconst logged = new Set((Array.isArray(logRows) ? logRows : []).map(r => String((r && r['Return ID']) ?? '')));\nconst text = v => v == null ? '' : (typeof v === 'object' ? String(v.description || v.name || v.message || JSON.stringify(v)) : String(v));\nconst parcel = v => v && typeof v === 'object' ? String(v.id ?? '') : text(v);\nconst rows = list\n  .filter(r => r && r.id != null && !logged.has(String(r.id)))\n  .map(r => ({\n    'Return ID': String(r.id),\n    'Created': r.created_at || '',\n    'Status': text(r.status),\n    'Reason': text(r.reason),\n    'Outbound parcel': parcel(r.outgoing_parcel),\n    'Return parcel': parcel(r.incoming_parcel),\n    'Refund': r.refund == null ? '' : (typeof r.refund === 'object' ? JSON.stringify(r.refund) : String(r.refund)),\n  }));\nreturn { rows, count: rows.length };\n"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "New returns",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Pick out new returns",
        "nextElementIds": [
          "538AE7E6-BFCF-4899-BDF5-98DFC7EE5D34"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Retrieves data from Google Sheets for AI agents to analyze spreadsheet content, process existing data, or extract information for automated workflows. Perfect for reading user submissions, analyzing data trends, or importing data for further processing.",
          "elementId": "EXTENSION:::SHARED:::default:::google-sheets:::getRows",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Read the returns log Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::google-sheets:::getRows",
          "legacyElementId": "JS###v1###GoogleSheets###getRows",
          "methodName": "getRows",
          "position": {
            "x": 433.8228778635949,
            "y": 110
          }
        },
        "flowElementId": "1BE2CA4E-49EF-4AC5-B4A0-AA23039897F1",
        "groupId": null,
        "id": "9DC1AEFF-3D7E-4D92-8101-DA89A72D4DE6",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "documentId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Returns log spreadsheet",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Returns log spreadsheet"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sheetId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 0
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "offset",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "limit",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "withRowNumbers",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Read the returns log', Error: The placeholder \"Returns log spreadsheet\" has no value",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getRows",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Returns log",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "google-sheets",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Read the returns log",
        "nextElementIds": [
          "039E8EBD-F56C-451D-88A0-5C9A6B3CFF3B"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Adds multiple data rows to Google Sheets in bulk for AI agents to efficiently store large datasets, batch process results, or import data from external sources. Essential for high-volume data operations and bulk data migration workflows.",
          "elementId": "EXTENSION:::SHARED:::default:::google-sheets:::addRows",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Add them to the returns log Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::google-sheets:::addRows",
          "legacyElementId": "JS###v1###GoogleSheets###addRows",
          "methodName": "addRows",
          "position": {
            "x": 433.5835033124889,
            "y": 436.8782673169251
          }
        },
        "flowElementId": "9246E865-19D0-421C-866D-53A9DD301A7D",
        "groupId": null,
        "id": "400A2919-57F9-45BA-B99A-4031355290CE",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "documentId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Returns log spreadsheet",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Returns log spreadsheet"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sheetId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 0
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "rows",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "New returns",
                    "subPathSegments": [
                      {
                        "key": "rows",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "039E8EBD-F56C-451D-88A0-5C9A6B3CFF3B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Add them to the returns log', Error: The placeholder \"Returns log spreadsheet\" has no value",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "addRows",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Logged rows",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "google-sheets",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Add them to the returns log",
        "nextElementIds": [
          "5B242432-13AB-40B8-A95B-5CBBF2252678"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 699.9125694541308,
            "y": 257.9113397264703
          }
        },
        "flowElementId": "C75D8779-CA91-4CC9-AF7E-E6CC617F34DB",
        "groupId": null,
        "id": "538AE7E6-BFCF-4899-BDF5-98DFC7EE5D34",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "651c54a7-9f63-4c64-bb02-c40c37b2c8d4",
                "nestedOperation": null,
                "operation": ">",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "New returns",
                      "subPathSegments": [
                        {
                          "key": "count",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "039E8EBD-F56C-451D-88A0-5C9A6B3CFF3B"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "INT",
                "values": [
                  {
                    "expression": [
                      {
                        "id": "NUMBER",
                        "label": null,
                        "type": "INPUT",
                        "value": 0
                      }
                    ],
                    "mode": "EXPRESSION",
                    "parseJsonString": false,
                    "resultType": null
                  }
                ]
              }
            ],
            "grouping": [
              "651c54a7-9f63-4c64-bb02-c40c37b2c8d4"
            ]
          },
          "elseComponent": {
            "componentId": "5B242432-13AB-40B8-A95B-5CBBF2252678",
            "componentType": "ELEMENT"
          },
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Has new returns",
          "storeResult": false,
          "thenComponent": {
            "componentId": "400A2919-57F9-45BA-B99A-4031355290CE",
            "componentType": "ELEMENT"
          }
        },
        "name": "Any new returns?",
        "nextElementIds": [
          "400A2919-57F9-45BA-B99A-4031355290CE",
          "5B242432-13AB-40B8-A95B-5CBBF2252678"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 925.2910082911277,
            "y": 608.5853640547368
          }
        },
        "flowElementId": "25A148B3-39EC-4911-8EB4-54587AECB98F",
        "groupId": null,
        "id": "212B85C3-E8ED-442C-8B72-50418CEA7564",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "d06869b2-425e-417d-8c12-1659ec06a40e",
                "nestedOperation": null,
                "operation": "isTrue",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Reason counts",
                      "subPathSegments": [
                        {
                          "key": "overThreshold",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "5B242432-13AB-40B8-A95B-5CBBF2252678"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "BOOLEAN",
                "values": []
              }
            ],
            "grouping": [
              "d06869b2-425e-417d-8c12-1659ec06a40e"
            ]
          },
          "elseComponent": null,
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Over threshold",
          "storeResult": false,
          "thenComponent": {
            "componentId": "E9F9208E-4FB0-4F8C-926F-34F60035D54A",
            "componentType": "ELEMENT"
          }
        },
        "name": "Reason over the threshold?",
        "nextElementIds": [
          "E9F9208E-4FB0-4F8C-926F-34F60035D54A"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "notes": "Retrieves a paginated list of return shipments created in your Sendcloud account. Returns include the outbound parcel reference, return status, reason, and any refund details. Supports pagination via page and page size.",
          "elementId": "EXTENSION:::SHARED:::default:::sendcloud:::listReturns",
          "isFirstElement": true,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Pull returns from Sendcloud Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sendcloud:::listReturns",
          "legacyElementId": "JS###v1###SendcloudService###listReturns",
          "methodName": "listReturns",
          "position": {
            "x": 110,
            "y": 110
          }
        },
        "flowElementId": "DBEDCA3B-9803-4EA8-A30D-CED87A319FAE",
        "groupId": null,
        "id": "580D67B2-F735-422C-9801-F0EA7E623195",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "page",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 1
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "pageSize",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 100
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "listReturns",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Sendcloud returns",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sendcloud",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Pull returns from Sendcloud",
        "nextElementIds": [
          "9DC1AEFF-3D7E-4D92-8101-DA89A72D4DE6"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Count return reasons this week Result"
          },
          "position": {
            "x": 905.9694372011769,
            "y": 439.7729036014531
          }
        },
        "flowElementId": "4AD1770D-87C9-4968-BFC9-84940B38C966",
        "groupId": null,
        "id": "5B242432-13AB-40B8-A95B-5CBBF2252678",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "logRows",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Returns log",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "9DC1AEFF-3D7E-4D92-8101-DA89A72D4DE6"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "newRows",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "New returns",
                    "subPathSegments": [
                      {
                        "key": "rows",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "039E8EBD-F56C-451D-88A0-5C9A6B3CFF3B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "threshold",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Alert threshold",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Alert threshold"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const since = Date.now() - 7 * 24 * 3600 * 1000;\nconst limit = Number(threshold) > 0 ? Number(threshold) : 5;\nconst tally = (rows) => {\n  const counts = {};\n  for (const r of (Array.isArray(rows) ? rows : [])) {\n    const t = Date.parse(r && r['Created']);\n    if (!Number.isFinite(t) || t < since) continue;\n    const reason = String(r['Reason'] || '').trim() || 'No reason given';\n    counts[reason] = (counts[reason] || 0) + 1;\n  }\n  return counts;\n};\nconst before = tally(logRows);\nconst after = tally([...(Array.isArray(logRows) ? logRows : []), ...(Array.isArray(newRows) ? newRows : [])]);\nconst crossed = Object.entries(after)\n  .filter(([reason, n]) => n >= limit && (before[reason] || 0) < limit)\n  .sort((a, b) => b[1] - a[1]);\nconst message = crossed.length\n  ? `Return reasons that reached ${limit} or more in the last 7 days:\\n` +\n    crossed.map(([reason, n]) => `• ${reason}: ${n} returns`).join('\\n') +\n    `\\nThe returns log in Google Sheets lists the parcels behind each one.`\n  : '';\nreturn { overThreshold: crossed.length > 0, message, counts: after };\n"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Reason counts",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Count return reasons this week",
        "nextElementIds": [
          "212B85C3-E8ED-442C-8B72-50418CEA7564"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      }
    ],
    "firstElementId": "580D67B2-F735-422C-9801-F0EA7E623195",
    "groups": [],
    "id": "28AA7088-489F-4A9A-B689-C789DDD4D9CF",
    "metaInfo": {
      "clientValidationState": {
        "errorMessage": "Please fix problems before start. Blocks with issues have red badge in the top-right corner of a block, hover it to see what needs to be done.",
        "valid": false
      },
      "errorMessage": "Please fix problems before start. Blocks with issues have red badge in the top-right corner of a block, hover it to see what needs to be done.",
      "executionStaticData": [
        {
          "description": "URL or ID of the Google Sheets spreadsheet that holds the returns log.",
          "error": null,
          "name": "Returns log spreadsheet",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "How many returns with the same reason in 7 days trigger a Slack alert.",
          "error": null,
          "name": "Alert threshold",
          "type": "INT",
          "value": ""
        }
      ],
      "initialData": null,
      "initialDataDefaultValues": {},
      "ownerFlowVersionId": null,
      "schedule": null,
      "sharedMemory": {
        "anchor": {
          "missingAnchorPolicy": null,
          "path": null,
          "type": "FLOW_MEMORY"
        },
        "expirationInSec": null
      },
      "wasLive": false
    }
  },
  "slaCalendars": [],
  "slaGoals": [],
  "subFlows": [],
  "exportDate": "2026-11-17T05:55:12.541Z"
}
