{
  "name": "QuietPass — recover CRM write only (OFF)",
  "flow": [
    {
      "id": 1,
      "module": "app#quietpass-kkwpuh:recoverAutomation",
      "version": 1,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "operationId": "REPLACE_ORIGINAL_OPERATION_ID"
      },
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Get a saved phone check"
        },
        "expect": [
          {
            "name": "operationId",
            "type": "text",
            "label": "Saved operation ID",
            "required": true
          }
        ],
        "interface": [
          {
            "name": "id",
            "label": "Saved operation ID",
            "type": "text"
          },
          {
            "name": "state",
            "label": "Operation state",
            "type": "text"
          },
          {
            "name": "quoteId",
            "label": "Original quote ID",
            "type": "text"
          },
          {
            "name": "maxSpend",
            "label": "Maximum amount",
            "type": "text"
          },
          {
            "name": "heldAmount",
            "label": "Amount reserved",
            "type": "text"
          },
          {
            "name": "chargedAmount",
            "label": "Charged amount",
            "type": "text"
          },
          {
            "name": "resultState",
            "label": "Saved result state",
            "type": "text"
          },
          {
            "name": "result",
            "label": "Phone check result",
            "type": "collection",
            "spec": [
              {
                "name": "requestId",
                "label": "Request ID",
                "type": "text"
              },
              {
                "name": "mode",
                "label": "Mode",
                "type": "text"
              },
              {
                "name": "simulated",
                "label": "Simulated",
                "type": "boolean"
              },
              {
                "name": "preparedAt",
                "label": "Prepared at",
                "type": "date"
              },
              {
                "name": "number",
                "label": "Phone number",
                "type": "collection",
                "spec": [
                  {
                    "name": "e164",
                    "label": "International number",
                    "type": "text"
                  },
                  {
                    "name": "national",
                    "label": "National number",
                    "type": "text"
                  },
                  {
                    "name": "international",
                    "label": "Formatted international number",
                    "type": "text"
                  },
                  {
                    "name": "country",
                    "label": "Country",
                    "type": "text"
                  },
                  {
                    "name": "valid",
                    "label": "Numbering plan valid",
                    "type": "boolean"
                  },
                  {
                    "name": "validationReason",
                    "label": "Validation reason",
                    "type": "text"
                  },
                  {
                    "name": "type",
                    "label": "Line type",
                    "type": "text"
                  },
                  {
                    "name": "typeReason",
                    "label": "Line type unavailable reason",
                    "type": "text"
                  },
                  {
                    "name": "carrier",
                    "label": "Current carrier",
                    "type": "text"
                  },
                  {
                    "name": "carrierReason",
                    "label": "Carrier unavailable reason",
                    "type": "text"
                  },
                  {
                    "name": "ported",
                    "label": "Ported",
                    "type": "boolean"
                  },
                  {
                    "name": "portedReason",
                    "label": "Porting unavailable reason",
                    "type": "text"
                  }
                ]
              },
              {
                "name": "contact",
                "label": "Contact options",
                "type": "collection",
                "spec": [
                  {
                    "name": "sms",
                    "label": "SMS support",
                    "type": "collection",
                    "spec": [
                      {
                        "name": "supported",
                        "label": "Supported",
                        "type": "boolean"
                      },
                      {
                        "name": "assumed",
                        "label": "Assumed from line type",
                        "type": "boolean"
                      },
                      {
                        "name": "basis",
                        "label": "Evidence basis",
                        "type": "text"
                      },
                      {
                        "name": "reason",
                        "label": "Unavailable reason",
                        "type": "text"
                      }
                    ]
                  },
                  {
                    "name": "whatsapp",
                    "label": "WhatsApp registration",
                    "type": "collection",
                    "spec": [
                      {
                        "name": "registered",
                        "label": "Registered",
                        "type": "boolean"
                      },
                      {
                        "name": "reason",
                        "label": "Unavailable reason",
                        "type": "text"
                      }
                    ]
                  },
                  {
                    "name": "telegram",
                    "label": "Telegram registration",
                    "type": "collection",
                    "spec": [
                      {
                        "name": "registered",
                        "label": "Registered",
                        "type": "boolean"
                      },
                      {
                        "name": "reason",
                        "label": "Unavailable reason",
                        "type": "text"
                      }
                    ]
                  }
                ]
              },
              {
                "name": "network",
                "label": "Network status",
                "type": "collection",
                "spec": [
                  {
                    "name": "reachable",
                    "label": "Reachable",
                    "type": "boolean"
                  },
                  {
                    "name": "reason",
                    "label": "Unavailable reason",
                    "type": "text"
                  }
                ]
              },
              {
                "name": "billing",
                "label": "Charge receipt",
                "type": "collection",
                "spec": [
                  {
                    "name": "currency",
                    "label": "Currency",
                    "type": "text"
                  },
                  {
                    "name": "amount",
                    "label": "Billed amount",
                    "type": "text"
                  }
                ]
              }
            ]
          }
        ]
      }
    },
    {
      "id": 2,
      "module": "hubspotcrm:MakeAPICall",
      "version": 2,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "headers": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "/crm/v3/objects/contacts/REPLACE_ORIGINAL_CONTACT_ID",
        "method": "GET",
        "qs": [
          {
            "key": "properties",
            "value": "phone,hs_country_region_code,qp_phone_e164,qp_phone_request_id"
          },
          {
            "key": "propertiesWithHistory",
            "value": "phone"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Read current source phone and its change history"
        }
      },
      "filter": {
        "name": "Only a settled retained result may be written",
        "conditions": [
          [
            {
              "a": "{{1.state}}",
              "o": "text:equal",
              "b": "settled"
            },
            {
              "a": "{{1.resultState}}",
              "o": "text:equal",
              "b": "settled"
            },
            {
              "a": "{{1.result.requestId}}",
              "o": "exist"
            }
          ]
        ]
      }
    },
    {
      "id": 3,
      "module": "app#quietpass-kkwpuh:formatPhone",
      "version": 1,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "phone": "{{2.body.properties.phone}}",
        "defaultCountry": "{{2.body.properties.hs_country_region_code}}"
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Format a phone number"
        },
        "expect": [
          {
            "name": "phone",
            "type": "text",
            "label": "Phone number",
            "required": true,
            "help": "Map one phone number. Use the country field for local numbers."
          },
          {
            "name": "defaultCountry",
            "type": "text",
            "label": "Default country for local numbers",
            "help": "Two-letter country code, such as GB or US. Leave blank for international input."
          }
        ],
        "interface": [
          {
            "name": "requestId",
            "label": "Request ID",
            "type": "text"
          },
          {
            "name": "mode",
            "label": "Mode",
            "type": "text"
          },
          {
            "name": "simulated",
            "label": "Simulated",
            "type": "boolean"
          },
          {
            "name": "preparedAt",
            "label": "Prepared at",
            "type": "date"
          },
          {
            "name": "number",
            "label": "Phone number",
            "type": "collection",
            "spec": [
              {
                "name": "e164",
                "label": "International number",
                "type": "text"
              },
              {
                "name": "national",
                "label": "National number",
                "type": "text"
              },
              {
                "name": "international",
                "label": "Formatted international number",
                "type": "text"
              },
              {
                "name": "country",
                "label": "Country",
                "type": "text"
              },
              {
                "name": "valid",
                "label": "Numbering plan valid",
                "type": "boolean"
              },
              {
                "name": "validationReason",
                "label": "Validation reason",
                "type": "text"
              },
              {
                "name": "type",
                "label": "Line type",
                "type": "text"
              },
              {
                "name": "typeReason",
                "label": "Line type unavailable reason",
                "type": "text"
              },
              {
                "name": "carrier",
                "label": "Current carrier",
                "type": "text"
              },
              {
                "name": "carrierReason",
                "label": "Carrier unavailable reason",
                "type": "text"
              },
              {
                "name": "ported",
                "label": "Ported",
                "type": "boolean"
              },
              {
                "name": "portedReason",
                "label": "Porting unavailable reason",
                "type": "text"
              }
            ]
          },
          {
            "name": "contact",
            "label": "Contact options",
            "type": "collection",
            "spec": [
              {
                "name": "sms",
                "label": "SMS support",
                "type": "collection",
                "spec": [
                  {
                    "name": "supported",
                    "label": "Supported",
                    "type": "boolean"
                  },
                  {
                    "name": "assumed",
                    "label": "Assumed from line type",
                    "type": "boolean"
                  },
                  {
                    "name": "basis",
                    "label": "Evidence basis",
                    "type": "text"
                  },
                  {
                    "name": "reason",
                    "label": "Unavailable reason",
                    "type": "text"
                  }
                ]
              },
              {
                "name": "whatsapp",
                "label": "WhatsApp registration",
                "type": "collection",
                "spec": [
                  {
                    "name": "registered",
                    "label": "Registered",
                    "type": "boolean"
                  },
                  {
                    "name": "reason",
                    "label": "Unavailable reason",
                    "type": "text"
                  }
                ]
              },
              {
                "name": "telegram",
                "label": "Telegram registration",
                "type": "collection",
                "spec": [
                  {
                    "name": "registered",
                    "label": "Registered",
                    "type": "boolean"
                  },
                  {
                    "name": "reason",
                    "label": "Unavailable reason",
                    "type": "text"
                  }
                ]
              }
            ]
          },
          {
            "name": "network",
            "label": "Network status",
            "type": "collection",
            "spec": [
              {
                "name": "reachable",
                "label": "Reachable",
                "type": "boolean"
              },
              {
                "name": "reason",
                "label": "Unavailable reason",
                "type": "text"
              }
            ]
          },
          {
            "name": "billing",
            "label": "Charge receipt",
            "type": "collection",
            "spec": [
              {
                "name": "currency",
                "label": "Currency",
                "type": "text"
              },
              {
                "name": "amount",
                "label": "Billed amount",
                "type": "text"
              }
            ]
          }
        ]
      },
      "onerror": [
        {
          "id": 103,
          "module": "builtin:Ignore",
          "version": 1,
          "parameters": {},
          "mapper": {},
          "metadata": {
            "designer": {
              "x": 600,
              "y": 250,
              "name": "Leave failed free formatting for review; never purchase"
            }
          }
        }
      ]
    },
    {
      "id": 4,
      "module": "hubspotcrm:MakeAPICall",
      "version": 2,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "headers": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "/crm/v3/objects/contacts/REPLACE_ORIGINAL_CONTACT_ID",
        "method": "PATCH",
        "body": "{\"properties\":{\"qp_phone_e164\":\"{{escapeJSON(if(1.result.number.e164 = null; emptystring; 1.result.number.e164))}}\",\"qp_phone_country\":\"{{escapeJSON(if(1.result.number.country = null; emptystring; 1.result.number.country))}}\",\"qp_phone_valid\":\"{{if(1.result.number.valid = null; emptystring; 1.result.number.valid)}}\",\"qp_phone_type\":\"{{escapeJSON(if(1.result.number.type = null; emptystring; 1.result.number.type))}}\",\"qp_phone_carrier\":\"{{escapeJSON(if(1.result.number.carrier = null; emptystring; 1.result.number.carrier))}}\",\"qp_phone_ported\":\"{{if(1.result.number.ported = null; emptystring; 1.result.number.ported)}}\",\"qp_phone_sms\":\"{{if(1.result.contact.sms.supported = null; emptystring; 1.result.contact.sms.supported)}}\",\"qp_phone_sms_basis\":\"{{escapeJSON(if(1.result.contact.sms.basis = null; emptystring; 1.result.contact.sms.basis))}}\",\"qp_phone_whatsapp\":\"{{if(1.result.contact.whatsapp.registered = null; emptystring; 1.result.contact.whatsapp.registered)}}\",\"qp_phone_telegram\":\"{{if(1.result.contact.telegram.registered = null; emptystring; 1.result.contact.telegram.registered)}}\",\"qp_phone_reachable\":\"{{if(1.result.network.reachable = null; emptystring; 1.result.network.reachable)}}\",\"qp_phone_status\":\"checked\",\"qp_phone_reason\":\"{{escapeJSON(if(ifempty(1.result.number.validationReason; ifempty(1.result.network.reason; emptystring)) = null; emptystring; ifempty(1.result.number.validationReason; ifempty(1.result.network.reason; emptystring))))}}\",\"qp_phone_checked_at\":\"{{escapeJSON(if(1.result.preparedAt = null; emptystring; 1.result.preparedAt))}}\",\"qp_phone_request_id\":\"{{escapeJSON(if(1.result.requestId = null; emptystring; 1.result.requestId))}}\"}}"
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0,
          "name": "Write only QuietPass fields if the source phone is unchanged"
        }
      },
      "filter": {
        "name": "Same source revision and phone; never overwrite a newer result",
        "conditions": [
          [
            {
              "a": "{{get(first(sort(2.body.propertiesWithHistory.phone; desc; \"timestamp\")); \"timestamp\")}}",
              "o": "text:equal",
              "b": "{{\"REPLACE_ORIGINAL_PHONE_REVISION\"}}"
            },
            {
              "a": "{{3.number.e164}}",
              "o": "text:equal",
              "b": "{{1.result.number.e164}}"
            },
            {
              "a": "{{2.body.properties.qp_phone_request_id}}",
              "o": "text:notequal",
              "b": "{{1.result.requestId}}"
            },
            {
              "a": "{{3.number.valid}}",
              "o": "text:equal",
              "b": "true"
            }
          ]
        ]
      }
    }
  ],
  "metadata": {
    "instant": false,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "slots": null,
      "confidential": false,
      "dataloss": false,
      "dlq": true,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "eu1.make.com",
    "notes": []
  }
}
