{
  "name": "Warp Notes → Salesforce",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Warp Notes webhook"
        },
        "restore": {
          "parameters": {
            "hook": {
              "data": {
                "editable": "true"
              },
              "label": "Warp Notes"
            }
          }
        },
        "parameters": [
          {
            "name": "hook",
            "type": "hook:gateway-webhook",
            "label": "Webhook",
            "required": true
          },
          {
            "name": "maxResults",
            "type": "number",
            "label": "Maximum number of results"
          }
        ],
        "interface": [
          {
            "name": "event",
            "type": "text"
          },
          {
            "name": "version",
            "type": "number"
          },
          {
            "name": "delivery_id",
            "type": "text"
          },
          {
            "name": "attempt",
            "type": "number"
          },
          {
            "name": "history",
            "type": "boolean"
          },
          {
            "name": "sent_at",
            "type": "text"
          },
          {
            "name": "workspace",
            "type": "collection",
            "spec": [
              {
                "name": "id",
                "type": "text"
              },
              {
                "name": "name",
                "type": "text"
              }
            ]
          },
          {
            "name": "note",
            "type": "collection",
            "spec": [
              {
                "name": "id",
                "type": "text"
              },
              {
                "name": "recorded_at",
                "type": "text"
              },
              {
                "name": "source",
                "type": "text"
              },
              {
                "name": "title",
                "type": "text"
              },
              {
                "name": "headline",
                "type": "text"
              },
              {
                "name": "summary",
                "type": "text"
              },
              {
                "name": "action_items",
                "type": "array",
                "spec": {
                  "type": "text"
                }
              },
              {
                "name": "transcript",
                "type": "text"
              },
              {
                "name": "captured_location",
                "type": "collection",
                "spec": [
                  {
                    "name": "lat",
                    "type": "number"
                  },
                  {
                    "name": "lng",
                    "type": "number"
                  }
                ]
              }
            ]
          },
          {
            "name": "company",
            "type": "collection",
            "spec": [
              {
                "name": "id",
                "type": "text"
              },
              {
                "name": "name",
                "type": "text"
              },
              {
                "name": "domain",
                "type": "text"
              },
              {
                "name": "phone",
                "type": "text"
              },
              {
                "name": "email",
                "type": "text"
              },
              {
                "name": "website",
                "type": "text"
              },
              {
                "name": "description",
                "type": "text"
              },
              {
                "name": "address",
                "type": "collection",
                "spec": [
                  {
                    "name": "text",
                    "type": "text"
                  },
                  {
                    "name": "lat",
                    "type": "number"
                  },
                  {
                    "name": "lng",
                    "type": "number"
                  }
                ]
              },
              {
                "name": "territory",
                "type": "text"
              },
              {
                "name": "labels",
                "type": "array",
                "spec": {
                  "type": "text"
                }
              }
            ]
          },
          {
            "name": "people",
            "type": "array",
            "spec": {
              "type": "collection",
              "spec": [
                {
                  "name": "id",
                  "type": "text"
                },
                {
                  "name": "name",
                  "type": "text"
                },
                {
                  "name": "title",
                  "type": "text"
                },
                {
                  "name": "company",
                  "type": "text"
                },
                {
                  "name": "emails",
                  "type": "array",
                  "spec": {
                    "type": "text"
                  }
                },
                {
                  "name": "phones",
                  "type": "array",
                  "spec": {
                    "type": "text"
                  }
                }
              ]
            }
          },
          {
            "name": "primary_person",
            "type": "collection",
            "spec": [
              {
                "name": "id",
                "type": "text"
              },
              {
                "name": "name",
                "type": "text"
              },
              {
                "name": "title",
                "type": "text"
              },
              {
                "name": "company",
                "type": "text"
              },
              {
                "name": "email",
                "type": "text"
              },
              {
                "name": "phone",
                "type": "text"
              }
            ]
          },
          {
            "name": "follow_ups",
            "type": "array",
            "spec": {
              "type": "collection",
              "spec": [
                {
                  "name": "id",
                  "type": "text"
                },
                {
                  "name": "title",
                  "type": "text"
                },
                {
                  "name": "due_local",
                  "type": "text"
                },
                {
                  "name": "time_zone",
                  "type": "text"
                },
                {
                  "name": "all_day",
                  "type": "boolean"
                },
                {
                  "name": "done",
                  "type": "boolean"
                },
                {
                  "name": "completed_at",
                  "type": "text"
                }
              ]
            }
          },
          {
            "name": "recorded_by",
            "type": "collection",
            "spec": [
              {
                "name": "user_id",
                "type": "text"
              },
              {
                "name": "name",
                "type": "text"
              },
              {
                "name": "email",
                "type": "text"
              }
            ]
          }
        ]
      }
    },
    {
      "id": 2,
      "module": "salesforce:makeApiCallV4",
      "version": 4,
      "parameters": {},
      "mapper": {
        "url": "/v60.0/query",
        "method": "GET",
        "headers": [],
        "qs": [
          {
            "key": "q",
            "value": "SELECT Id, AccountId FROM Contact WHERE Email = '{{replace(ifempty(lower(1.primary_person.email); \"none@none.invalid\"); \"'\"; \"\")}}' LIMIT 1"
          }
        ],
        "body": ""
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Find the contact by email"
        },
        "restore": {
          "expect": {
            "method": {
              "label": "GET"
            }
          }
        },
        "parameters": [
          {
            "name": "__IMTCONN__",
            "type": "account:salesforce,salesforce2",
            "label": "Connection",
            "required": true
          }
        ],
        "expect": [
          {
            "name": "url",
            "type": "text",
            "label": "URL",
            "required": true
          },
          {
            "name": "method",
            "type": "select",
            "label": "Method",
            "required": true,
            "validate": {
              "enum": [
                "GET",
                "POST",
                "PUT",
                "PATCH",
                "DELETE"
              ]
            }
          },
          {
            "name": "headers",
            "type": "array",
            "label": "Headers",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "qs",
            "type": "array",
            "label": "Query String",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "body",
            "type": "any",
            "label": "Body"
          }
        ]
      },
      "filter": {
        "name": "Only new notes",
        "conditions": [
          [
            {
              "a": "{{1.event}}",
              "b": "note.created",
              "o": "text:equal"
            }
          ]
        ]
      }
    },
    {
      "id": 3,
      "module": "salesforce:makeApiCallV4",
      "version": 4,
      "parameters": {},
      "mapper": {
        "url": "/v60.0/query",
        "method": "GET",
        "headers": [],
        "qs": [
          {
            "key": "q",
            "value": "SELECT Id FROM Account WHERE Website LIKE '%{{replace(ifempty(lower(1.company.domain); \"none.invalid\"); \"'\"; \"\")}}%' OR Name = '{{replace(ifempty(1.company.name; \"none.invalid\"); \"'\"; \"\")}}' LIMIT 1"
          }
        ],
        "body": ""
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Find the account by website domain or name"
        },
        "restore": {
          "expect": {
            "method": {
              "label": "GET"
            }
          }
        },
        "parameters": [
          {
            "name": "__IMTCONN__",
            "type": "account:salesforce,salesforce2",
            "label": "Connection",
            "required": true
          }
        ],
        "expect": [
          {
            "name": "url",
            "type": "text",
            "label": "URL",
            "required": true
          },
          {
            "name": "method",
            "type": "select",
            "label": "Method",
            "required": true,
            "validate": {
              "enum": [
                "GET",
                "POST",
                "PUT",
                "PATCH",
                "DELETE"
              ]
            }
          },
          {
            "name": "headers",
            "type": "array",
            "label": "Headers",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "qs",
            "type": "array",
            "label": "Query String",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "body",
            "type": "any",
            "label": "Body"
          }
        ]
      }
    },
    {
      "id": 4,
      "module": "salesforce:makeApiCallV4",
      "version": 4,
      "parameters": {},
      "mapper": {
        "url": "/v60.0/query",
        "method": "GET",
        "headers": [],
        "qs": [
          {
            "key": "q",
            "value": "SELECT Id FROM User WHERE Email = '{{replace(ifempty(lower(1.recorded_by.email); \"none@none.invalid\"); \"'\"; \"\")}}' AND IsActive = true LIMIT 1"
          }
        ],
        "body": ""
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0,
          "name": "Find the rep (User) by email"
        },
        "restore": {
          "expect": {
            "method": {
              "label": "GET"
            }
          }
        },
        "parameters": [
          {
            "name": "__IMTCONN__",
            "type": "account:salesforce,salesforce2",
            "label": "Connection",
            "required": true
          }
        ],
        "expect": [
          {
            "name": "url",
            "type": "text",
            "label": "URL",
            "required": true
          },
          {
            "name": "method",
            "type": "select",
            "label": "Method",
            "required": true,
            "validate": {
              "enum": [
                "GET",
                "POST",
                "PUT",
                "PATCH",
                "DELETE"
              ]
            }
          },
          {
            "name": "headers",
            "type": "array",
            "label": "Headers",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "qs",
            "type": "array",
            "label": "Query String",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "body",
            "type": "any",
            "label": "Body"
          }
        ]
      }
    },
    {
      "id": 5,
      "module": "json:TransformToJSON",
      "version": 1,
      "parameters": {
        "space": ""
      },
      "mapper": {
        "object": "{{1.note.title}}"
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": -300,
          "name": "Escape the subject"
        },
        "restore": {
          "parameters": {
            "space": {
              "label": "Empty"
            }
          }
        },
        "parameters": [
          {
            "name": "space",
            "type": "select",
            "label": "Indentation",
            "validate": {
              "enum": [
                "tab",
                "2",
                "4"
              ]
            }
          }
        ],
        "expect": [
          {
            "name": "object",
            "type": "any",
            "label": "Object"
          }
        ]
      }
    },
    {
      "id": 6,
      "module": "json:TransformToJSON",
      "version": 1,
      "parameters": {
        "space": ""
      },
      "mapper": {
        "object": "{{1.note.summary}}{{newline}}{{newline}}{{if(length(1.note.action_items) > 0; \"Action items:\"; emptystring)}}{{newline}}{{join(1.note.action_items; newline)}}{{newline}}{{newline}}Recorded by {{1.recorded_by.name}} in Warp Notes"
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": -150,
          "name": "Escape the description"
        },
        "restore": {
          "parameters": {
            "space": {
              "label": "Empty"
            }
          }
        },
        "parameters": [
          {
            "name": "space",
            "type": "select",
            "label": "Indentation",
            "validate": {
              "enum": [
                "tab",
                "2",
                "4"
              ]
            }
          }
        ],
        "expect": [
          {
            "name": "object",
            "type": "any",
            "label": "Object"
          }
        ]
      }
    },
    {
      "id": 7,
      "module": "json:TransformToJSON",
      "version": 1,
      "parameters": {
        "space": ""
      },
      "mapper": {
        "object": "{{2.body.records[1].Id}}"
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 0,
          "name": "Escape the contact id"
        },
        "restore": {
          "parameters": {
            "space": {
              "label": "Empty"
            }
          }
        },
        "parameters": [
          {
            "name": "space",
            "type": "select",
            "label": "Indentation",
            "validate": {
              "enum": [
                "tab",
                "2",
                "4"
              ]
            }
          }
        ],
        "expect": [
          {
            "name": "object",
            "type": "any",
            "label": "Object"
          }
        ]
      }
    },
    {
      "id": 8,
      "module": "json:TransformToJSON",
      "version": 1,
      "parameters": {
        "space": ""
      },
      "mapper": {
        "object": "{{ifempty(2.body.records[1].AccountId; 3.body.records[1].Id)}}"
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 150,
          "name": "Escape the account id"
        },
        "restore": {
          "parameters": {
            "space": {
              "label": "Empty"
            }
          }
        },
        "parameters": [
          {
            "name": "space",
            "type": "select",
            "label": "Indentation",
            "validate": {
              "enum": [
                "tab",
                "2",
                "4"
              ]
            }
          }
        ],
        "expect": [
          {
            "name": "object",
            "type": "any",
            "label": "Object"
          }
        ]
      }
    },
    {
      "id": 9,
      "module": "json:TransformToJSON",
      "version": 1,
      "parameters": {
        "space": ""
      },
      "mapper": {
        "object": "{{add(emptyarray; \"OwnerId\"; 4.body.records[1].Id)}}"
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 300,
          "name": "Escape the user id"
        },
        "restore": {
          "parameters": {
            "space": {
              "label": "Empty"
            }
          }
        },
        "parameters": [
          {
            "name": "space",
            "type": "select",
            "label": "Indentation",
            "validate": {
              "enum": [
                "tab",
                "2",
                "4"
              ]
            }
          }
        ],
        "expect": [
          {
            "name": "object",
            "type": "any",
            "label": "Object"
          }
        ]
      }
    },
    {
      "id": 10,
      "module": "salesforce:makeApiCallV4",
      "version": 4,
      "parameters": {},
      "mapper": {
        "url": "/v60.0/sobjects/Task",
        "method": "POST",
        "headers": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "qs": [],
        "body": "{\"Subject\":{{5.json}},\"Status\":\"Completed\",\"Priority\":\"Normal\",\"ActivityDate\":\"{{formatDate(1.note.recorded_at; \"YYYY-MM-DD\")}}\",\"Description\":{{6.json}},\"WhoId\":{{if(length(2.body.records) > 0; 7.json; \"null\")}},\"WhatId\":{{if(length(toString(ifempty(2.body.records[1].AccountId; 3.body.records[1].Id))) > 0; 8.json; \"null\")}}{{if(length(4.body.records) > 0; \",\"; emptystring)}}{{if(length(4.body.records) > 0; replace(substring(9.json; 1; length(9.json) - 1); \",\"; \":\"); emptystring)}}}"
      },
      "metadata": {
        "designer": {
          "x": 1500,
          "y": 0,
          "name": "Log the note as a completed Task"
        },
        "restore": {
          "expect": {
            "method": {
              "label": "POST"
            }
          }
        },
        "parameters": [
          {
            "name": "__IMTCONN__",
            "type": "account:salesforce,salesforce2",
            "label": "Connection",
            "required": true
          }
        ],
        "expect": [
          {
            "name": "url",
            "type": "text",
            "label": "URL",
            "required": true
          },
          {
            "name": "method",
            "type": "select",
            "label": "Method",
            "required": true,
            "validate": {
              "enum": [
                "GET",
                "POST",
                "PUT",
                "PATCH",
                "DELETE"
              ]
            }
          },
          {
            "name": "headers",
            "type": "array",
            "label": "Headers",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "qs",
            "type": "array",
            "label": "Query String",
            "spec": [
              {
                "name": "key",
                "type": "text",
                "label": "Key"
              },
              {
                "name": "value",
                "type": "text",
                "label": "Value"
              }
            ]
          },
          {
            "name": "body",
            "type": "any",
            "label": "Body"
          }
        ]
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "slots": null,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    }
  }
}
