跳转到主要内容
自动将交易数据发送到您的开票系统(Stripe、QuickBooks、Xero 等) 当机会赢单时。

工作流结构

  1. 触发器:记录已更新(机会对象)
  2. 筛选器:阶段 = 赢单
  3. 搜索记录:获取公司详细信息
  4. 代码(可选):格式化负载
  5. HTTP 请求:发送到开票系统

步骤 1:设置触发器

  1. 创建新的工作流
  2. 选择 记录已更新 触发器
  3. 选择 机会 作为对象

步骤 2:筛选赢单

添加一个 筛选 操作,仅在机会赢单时才继续:
设置
字段阶段
条件等于
CLOSED_WON(或您的阶段名称)
该触发器会在任何机会更新时触发。 筛选器确保仅当阶段变更为赢单时,工作流才会继续。

步骤 3:获取公司详细信息

机会记录可能不包含开票所需的所有公司字段。 添加一个 搜索记录 操作:
设置
对象公司
匹配方式ID 等于 {{trigger.object.companyId}}
这将检索包含账单地址、税号等在内的完整公司记录。

步骤 4:格式化负载(可选)

如果您的开票系统需要特定格式,请添加一个 代码 操作:
export const main = async (params: {
  opportunity: any;
  company: any;
}): Promise<object> => {
  const { opportunity, company } = params;

  return {
    invoice: {
      // Customer info from Company
      customer_name: company.name,
      customer_email: company.email || "",
      billing_address: {
        line1: company.address?.street || "",
        city: company.address?.city || "",
        postal_code: company.address?.postalCode || "",
        country: company.address?.country || ""
      },
      tax_id: company.taxId || null,

      // Invoice details from Opportunity
      amount: opportunity.amount,
      currency: opportunity.currency || "USD",
      description: `Invoice for ${opportunity.name}`,
      due_days: 30,

      // Reference back to Twenty
      metadata: {
        opportunity_id: opportunity.id,
        company_id: company.id
      }
    }
  };
};

步骤 5:发送到开票系统

添加一个 HTTP 请求 操作:
设置
方法POST
URL您的开票 API 端点
请求头Authorization: Bearer YOUR_API_KEY
请求体{{code.invoice}} 或直接映射字段

示例:Stripe 发票

POST https://api.stripe.com/v1/invoices
Headers:
  Authorization: Bearer sk_live_xxx
  Content-Type: application/x-www-form-urlencoded

Body:
  customer: {{company.stripeCustomerId}}
  collection_method: send_invoice
  days_until_due: 30

示例:QuickBooks 发票

POST https://quickbooks.api.intuit.com/v3/company/{realmId}/invoice
Headers:
  Authorization: Bearer YOUR_ACCESS_TOKEN
  Content-Type: application/json

Body: {{code.invoice}}

完整的工作流摘要

步骤操作目的
1触发器:记录已更新当任何机会发生更改时触发
2过滤仅当阶段 = 赢单时才继续
3搜索记录获取用于开票的完整公司详细信息
4代码为开票 API 格式化数据
5HTTP请求在外部系统中创建发票

提示

  • 存储外部 ID:使用 更新记录 操作将 API 返回的发票 ID 保存回机会
  • 错误处理:添加一个分支,在 HTTP 请求失败时发送通知
  • 先测试:在上线之前,使用开票系统的沙盒/测试模式

相关内容