{
  "elementsLearnedData": [],
  "elementsTestData": [],
  "flow": {
    "id": "FCD5402E-3DEE-4702-8E2C-89985B3EFDE0",
    "name": "FreshBooks: shipped order to sent invoice"
  },
  "flowVersion": {
    "clientMetadata": {
      "viewport": {
        "x": 250.681232357885,
        "y": -110.83618852948985,
        "zoom": 0.6551967019291817
      },
      "autoSave": true,
      "descriptions": {
        "flow": "When a Shopify order on payment terms ships, finds or adds the client in FreshBooks, creates the invoice with the order's lines, shipping, discounts and tax, and emails it to the client.",
        "initialData": "",
        "initialDataFields": {}
      }
    },
    "description": "When a Shopify order on payment terms ships, finds or adds the client in FreshBooks, creates the invoice with the order's lines, shipping, discounts and tax, and emails it to the client.",
    "elements": [
      {
        "clientMetadata": {
          "notes": "Adds a new client, the person or business you invoice. Use this when onboarding a new customer.",
          "elementId": "EXTENSION:::SHARED:::default:::freshbooks:::createClient",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Add the client to FreshBooks Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::freshbooks:::createClient",
          "legacyElementId": "JS###v1###FreshBooksService###createClient",
          "methodName": "createClient",
          "position": {
            "x": 69.89201985076602,
            "y": 664.193707325056
          }
        },
        "flowElementId": "91EF6568-83D1-41D8-A996-042254EF36EF",
        "groupId": null,
        "id": "99916A4B-C178-4244-A967-BBF9EE96FC1A",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "firstName",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "firstName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "lastName",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "lastName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "organization",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "company",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "email",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "email",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "phone",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "phone",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "currency",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Full order",
                    "subPathSegments": [
                      {
                        "key": "currency",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DFED579E-441D-41C7-9050-1ACA10565F05"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "addressLine1",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "address1",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "addressLine2",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "address2",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "city",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "city",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "state",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "state",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "postalCode",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "postalCode",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "country",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "country",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "notes",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Added from Shopify order "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Full order",
                    "subPathSegments": [
                      {
                        "key": "name",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DFED579E-441D-41C7-9050-1ACA10565F05"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Add the client to FreshBooks', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "createClient",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "New client",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "freshbooks",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Add the client to FreshBooks",
        "nextElementIds": [
          "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 769.3364947092643,
            "y": 675.206232015404
          }
        },
        "flowElementId": "CABF55E8-3822-4FE0-AFAC-4656E5B60083",
        "groupId": null,
        "id": "A431092E-188D-429B-B6F0-F0D1973AE7DD",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "545bdda8-e5a0-4a4d-b5e2-1e50b62b53b3",
                "nestedOperation": null,
                "operation": "isTrue",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Invoice prep",
                      "subPathSegments": [
                        {
                          "key": "needsInvoice",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "BOOLEAN",
                "values": []
              }
            ],
            "grouping": [
              "545bdda8-e5a0-4a4d-b5e2-1e50b62b53b3"
            ]
          },
          "elseComponent": null,
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "notyet",
          "storeResult": false,
          "thenComponent": {
            "componentId": "8B85C4A9-C0FC-40F5-84D9-4B6DA701D68C",
            "componentType": "ELEMENT"
          }
        },
        "name": "Not invoiced yet?",
        "nextElementIds": [
          "8B85C4A9-C0FC-40F5-84D9-4B6DA701D68C"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Prepare the invoice Result"
          },
          "position": {
            "x": 465.85082819298225,
            "y": 675.206232015404
          }
        },
        "flowElementId": "7C2508AB-7AAD-44D2-B14D-085B0D3432D1",
        "groupId": null,
        "id": "76FBF169-66E6-4177-BEC4-63CFF59BC6A0",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "order",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Full order",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "DFED579E-441D-41C7-9050-1ACA10565F05"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "match",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "created",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "New client",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "99916A4B-C178-4244-A967-BBF9EE96FC1A"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "invoices",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client invoices",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "4BA46F56-A515-40EF-9790-68880D7A80E1"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "termsDays",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Payment terms in days",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Payment terms in days"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const num = v => Number(v || 0);\nconst round = v => Math.round(v * 100) / 100;\nconst has = v => v !== undefined && v !== null && v !== '';\nconst clientId = match.found ? match.clientId : String((created && (created.id || created.userid)) || '');\nconst earlier = Array.isArray(invoices) ? invoices : [];\nconst alreadyInvoiced = Boolean(match.found) && earlier.some(i => String(i.po_number || '') === String(order.name) && i.vis_state !== 1);\nconst lines = [];\nfor (const li of order.lineItems || []) {\n  const qty = num(li.quantity);\n  if (!qty) continue;\n  const variant = li.variantTitle && li.variantTitle !== 'Default Title' ? li.variantTitle : null;\n  lines.push({\n    description: [li.title, variant, li.sku ? 'SKU ' + li.sku : null].filter(Boolean).join(' / '),\n    quantity: qty,\n    unitPrice: round(num(li.totalPrice) / qty),\n  });\n}\nfor (const s of order.shippingLines || []) {\n  const price = num(has(s.discountedPrice) ? s.discountedPrice : s.price);\n  if (price) lines.push({ description: 'Shipping: ' + (s.title || 'shipping'), quantity: 1, unitPrice: round(price) });\n}\nconst lineDiscounts = (order.lineItems || []).reduce((t, li) => t + num(li.totalPrice) - num(has(li.discountedPrice) ? li.discountedPrice : li.totalPrice), 0);\nif (round(lineDiscounts) > 0) lines.push({ description: 'Discounts', quantity: 1, unitPrice: -round(lineDiscounts) });\nif (num(order.totalTax) > 0) lines.push({ description: 'Sales tax', quantity: 1, unitPrice: round(num(order.totalTax)) });\nconst sum = lines.reduce((t, l) => t + l.quantity * l.unitPrice, 0);\nconst diff = round(num(order.totalPrice) - sum);\nif (Math.abs(diff) >= 0.01) lines.push({ description: 'Order discounts and adjustments', quantity: 1, unitPrice: diff });\nconst dueDate = new Date(Date.now() + num(termsDays) * 86400000).toISOString().slice(0, 10);\nreturn {\n  clientId,\n  needsInvoice: Boolean(clientId) && !alreadyInvoiced && lines.length > 0,\n  alreadyInvoiced,\n  lines,\n  dueDate,\n  poNumber: String(order.name || ''),\n  currency: order.currency || '',\n};"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Invoice prep",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Prepare the invoice",
        "nextElementIds": [
          "A431092E-188D-429B-B6F0-F0D1973AE7DD"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Retrieves a single order by its ID with full details: line items with their product, sellable stock, weight and tax lines, shipping method, customer, addresses, total weight and custom attributes.",
          "elementId": "EXTENSION:::SHARED:::default:::shopify:::getOrder",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Read the full order Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::shopify:::getOrder",
          "legacyElementId": "JS###v1###Shopify###getOrder",
          "methodName": "getOrder",
          "position": {
            "x": 750.2098698964427,
            "y": 123.97901301035571
          }
        },
        "flowElementId": "C705B235-94A8-4E63-A677-F917B61C1AFA",
        "groupId": null,
        "id": "DFED579E-441D-41C7-9050-1ACA10565F05",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "orderId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "RESULT",
                    "label": "Order update",
                    "subPathSegments": [
                      {
                        "key": "id",
                        "optional": false
                      }
                    ],
                    "type": "TRIGGER_DATA",
                    "value": "A1AB6AD7-58D0-4F82-B872-7695E59DFD0E"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Read the full order', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getOrder",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Full order",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "shopify",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Read the full order",
        "nextElementIds": [
          "74CD53F4-6BB2-44BA-8E84-CA86728C1837"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Sends an invoice to your client by email, or simply marks it as sent. Use this after creating a draft.",
          "elementId": "EXTENSION:::SHARED:::default:::freshbooks:::sendInvoice",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Email the invoice to the client Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::freshbooks:::sendInvoice",
          "legacyElementId": "JS###v1###FreshBooksService###sendInvoice",
          "methodName": "sendInvoice",
          "position": {
            "x": 742.4815014765709,
            "y": 1016.2009424985363
          }
        },
        "flowElementId": "63851D4B-048F-4365-92B1-C6A1B794C04D",
        "groupId": null,
        "id": "FFD58473-815B-47BD-9F09-490CA329B3CB",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "invoiceId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "New invoice",
                    "subPathSegments": [
                      {
                        "key": "invoiceid",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "8B85C4A9-C0FC-40F5-84D9-4B6DA701D68C"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sendMethod",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "email"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "recipients",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "subject",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "message",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "includePdf",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_TRUE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": true
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Email the invoice to the client', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "sendInvoice",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Sent invoice",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "freshbooks",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Email the invoice to the client",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Triggers when an existing order is updated in your Shopify store. Polling interval can be customized (minimum 30 seconds). Each cycle inspects the 50 most recently updated orders, so more than 50 updates between polls may be missed.",
          "elementId": "EXTENSION:::SHARED:::default:::shopify:::onOrderUpdated",
          "isFirstElement": true,
          "blockDefinitionId": "EXTENSION:::SHARED:::default:::shopify:::onOrderUpdated",
          "newElementId": "EXTENSION:::SHARED:::default:::shopify:::onOrderUpdated",
          "legacyElementId": "JS###v1###Shopify###onOrderUpdated",
          "methodName": "onOrderUpdated",
          "position": {
            "x": 110,
            "y": 130
          }
        },
        "flowElementId": "27EB76ED-673B-437C-AA9B-FE2ED675318F",
        "groupId": null,
        "id": "A1AB6AD7-58D0-4F82-B872-7695E59DFD0E",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": "Block: 'Order updated in Shopify', Error: OAuth Connection is required",
            "valid": false
          },
          "condition": null,
          "connectionId": null,
          "dynamicData": [],
          "eventName": "onOrderUpdated",
          "frequency": {
            "repeat": {
              "every": 300
            },
            "schedule": "custom"
          },
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": null
          },
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Order update",
          "serviceId": "shopify",
          "slaConditions": [],
          "staticData": {},
          "storeResult": true,
          "subtype": "POLLING",
          "type": "CUSTOM"
        },
        "name": "Order updated in Shopify",
        "nextElementIds": [
          "CB9916EE-7ED9-47CE-B615-81F68F4B2BA2"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "TRIGGER"
      },
      {
        "clientMetadata": {
          "notes": "Lists your clients, with optional filters. Use this to look up customers or pull a list to work through.",
          "elementId": "EXTENSION:::SHARED:::default:::freshbooks:::findClients",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Find the client in FreshBooks Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::freshbooks:::findClients",
          "legacyElementId": "JS###v1###FreshBooksService###findClients",
          "methodName": "findClients",
          "position": {
            "x": 725.6132996875294,
            "y": 268.48270076181825
          }
        },
        "flowElementId": "1435645E-A467-4850-9A92-41A097903CD1",
        "groupId": null,
        "id": "74CD53F4-6BB2-44BA-8E84-CA86728C1837",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "search",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Full order",
                    "subPathSegments": [
                      {
                        "key": "email",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DFED579E-441D-41C7-9050-1ACA10565F05"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "onlyWithOutstanding",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "maxResults",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 100
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Find the client in FreshBooks', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "findClients",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Clients",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "freshbooks",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Find the client in FreshBooks",
        "nextElementIds": [
          "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Lists invoices, with optional filters by client, status, and date. Use this to find invoices to act on or report.",
          "elementId": "EXTENSION:::SHARED:::default:::freshbooks:::findInvoices",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Find the client's invoices Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::freshbooks:::findInvoices",
          "legacyElementId": "JS###v1###FreshBooksService###findInvoices",
          "methodName": "findInvoices",
          "position": {
            "x": 449.4172060947044,
            "y": 453.109378352876
          }
        },
        "flowElementId": "6137856E-81E1-458F-8257-AE7B01E1A228",
        "groupId": null,
        "id": "4BA46F56-A515-40EF-9790-68880D7A80E1",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "clientId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Client match",
                    "subPathSegments": [
                      {
                        "key": "clientId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "status",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "fromDate",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "toDate",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "maxResults",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 100
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Find the client's invoices', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "findInvoices",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Client invoices",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "freshbooks",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Find the client's invoices",
        "nextElementIds": [
          "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Creates a new invoice for a client with one or more line items. The invoice starts as a draft, use Send Invoice to deliver it.",
          "elementId": "EXTENSION:::SHARED:::default:::freshbooks:::createInvoice",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Create the invoice Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::freshbooks:::createInvoice",
          "legacyElementId": "JS###v1###FreshBooksService###createInvoice",
          "methodName": "createInvoice",
          "position": {
            "x": 772.2844502912601,
            "y": 850.519896727071
          }
        },
        "flowElementId": "8B7F7393-12FF-4910-A238-003A981AAA71",
        "groupId": null,
        "id": "8B85C4A9-C0FC-40F5-84D9-4B6DA701D68C",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "clientId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice prep",
                    "subPathSegments": [
                      {
                        "key": "clientId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "lineItems",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice prep",
                    "subPathSegments": [
                      {
                        "key": "lines",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "invoiceDate",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "dueDate",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice prep",
                    "subPathSegments": [
                      {
                        "key": "dueDate",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "currency",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice prep",
                    "subPathSegments": [
                      {
                        "key": "currency",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "invoiceNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "poNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice prep",
                    "subPathSegments": [
                      {
                        "key": "poNumber",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "76FBF169-66E6-4177-BEC4-63CFF59BC6A0"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "discountPercent",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "notes",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Shopify order "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Full order",
                    "subPathSegments": [
                      {
                        "key": "name",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DFED579E-441D-41C7-9050-1ACA10565F05"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "terms",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Create the invoice', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "createInvoice",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "New invoice",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "freshbooks",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Create the invoice",
        "nextElementIds": [
          "FFD58473-815B-47BD-9F09-490CA329B3CB"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Match the client by email Result"
          },
          "position": {
            "x": 405.988366986047,
            "y": 285.04041498334
          }
        },
        "flowElementId": "7BB9D337-AA32-4B8D-8FF5-164D5DBF4B56",
        "groupId": null,
        "id": "D4342856-CB9F-4BC0-BFFC-4930332C2C97",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "order",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Full order",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "DFED579E-441D-41C7-9050-1ACA10565F05"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "clients",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Clients",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "74CD53F4-6BB2-44BA-8E84-CA86728C1837"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const email = String(order.email || (order.customer && order.customer.email) || '').trim().toLowerCase();\nconst list = Array.isArray(clients) ? clients : [];\nconst hit = email ? list.find(c => String(c.email || '').trim().toLowerCase() === email) : null;\nconst b = order.billingAddress || order.shippingAddress || {};\nconst name = String((order.customer && order.customer.displayName) || '').trim();\nreturn {\n  found: Boolean(hit),\n  clientId: hit ? String(hit.id) : '',\n  email,\n  firstName: b.firstName || name.split(' ')[0] || '',\n  lastName: b.lastName || name.split(' ').slice(1).join(' '),\n  company: b.company || '',\n  phone: order.phone || (order.customer && order.customer.phone) || b.phone || '',\n  address1: b.address1 || '',\n  address2: b.address2 || '',\n  city: b.city || '',\n  state: b.province || '',\n  postalCode: b.zip || '',\n  country: b.country || '',\n};"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Client match",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Match the client by email",
        "nextElementIds": [
          "402FE1D3-53DB-4E3F-85E3-305C4811E487"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 90.06234972525375,
            "y": 284.12190304322377
          }
        },
        "flowElementId": "C676F61B-004E-4BB7-AD7D-61D75F132229",
        "groupId": null,
        "id": "402FE1D3-53DB-4E3F-85E3-305C4811E487",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "6b022eef-44dc-41d3-94e6-6de0947e8acf",
                "nestedOperation": null,
                "operation": "isTrue",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Client match",
                      "subPathSegments": [
                        {
                          "key": "found",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "D4342856-CB9F-4BC0-BFFC-4930332C2C97"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "BOOLEAN",
                "values": []
              }
            ],
            "grouping": [
              "6b022eef-44dc-41d3-94e6-6de0947e8acf"
            ]
          },
          "elseComponent": {
            "componentId": "99916A4B-C178-4244-A967-BBF9EE96FC1A",
            "componentType": "ELEMENT"
          },
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "found",
          "storeResult": false,
          "thenComponent": {
            "componentId": "4BA46F56-A515-40EF-9790-68880D7A80E1",
            "componentType": "ELEMENT"
          }
        },
        "name": "Client in FreshBooks?",
        "nextElementIds": [
          "99916A4B-C178-4244-A967-BBF9EE96FC1A",
          "4BA46F56-A515-40EF-9790-68880D7A80E1"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 400,
            "y": 130
          }
        },
        "flowElementId": "A818D165-FC24-4BAE-AF02-7BF5BBFB99CA",
        "groupId": null,
        "id": "CB9916EE-7ED9-47CE-B615-81F68F4B2BA2",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "7e60672f-da57-4304-b3a1-dbeaddc63abc",
                "nestedOperation": null,
                "operation": "equal",
                "property": {
                  "expression": [
                    {
                      "id": "RESULT",
                      "label": "Order update",
                      "subPathSegments": [
                        {
                          "key": "fulfillmentStatus",
                          "optional": false
                        }
                      ],
                      "type": "TRIGGER_DATA",
                      "value": "A1AB6AD7-58D0-4F82-B872-7695E59DFD0E"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "STRING",
                "values": [
                  {
                    "expression": [
                      {
                        "id": "TEXT",
                        "label": null,
                        "type": "INPUT",
                        "value": "FULFILLED"
                      }
                    ],
                    "mode": "EXPRESSION",
                    "parseJsonString": false,
                    "resultType": null
                  }
                ]
              },
              {
                "id": "825e4483-062e-4712-ad21-638f7455a448",
                "nestedOperation": null,
                "operation": "equal",
                "property": {
                  "expression": [
                    {
                      "id": "RESULT",
                      "label": "Order update",
                      "subPathSegments": [
                        {
                          "key": "financialStatus",
                          "optional": false
                        }
                      ],
                      "type": "TRIGGER_DATA",
                      "value": "A1AB6AD7-58D0-4F82-B872-7695E59DFD0E"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "STRING",
                "values": [
                  {
                    "expression": [
                      {
                        "id": "TEXT",
                        "label": null,
                        "type": "INPUT",
                        "value": "PENDING"
                      }
                    ],
                    "mode": "EXPRESSION",
                    "parseJsonString": false,
                    "resultType": null
                  }
                ]
              }
            ],
            "grouping": [
              "7e60672f-da57-4304-b3a1-dbeaddc63abc",
              "AND",
              "825e4483-062e-4712-ad21-638f7455a448"
            ]
          },
          "elseComponent": null,
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "shipped",
          "storeResult": false,
          "thenComponent": {
            "componentId": "DFED579E-441D-41C7-9050-1ACA10565F05",
            "componentType": "ELEMENT"
          }
        },
        "name": "Shipped and not yet paid?",
        "nextElementIds": [
          "DFED579E-441D-41C7-9050-1ACA10565F05"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      }
    ],
    "firstElementId": "A1AB6AD7-58D0-4F82-B872-7695E59DFD0E",
    "groups": [],
    "id": "B3EE321A-9AF5-4132-BBC7-D098E9395F6C",
    "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": "Days until the FreshBooks invoice is due.",
          "error": null,
          "name": "Payment terms in days",
          "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-18T10:19:04.336Z"
}
