> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Close CRM

> 将 Dodo Payments 数据与 Close CRM 同步，以跟踪潜在客户并管理销售管道。

## 介绍

将您的支付数据直接连接到 Close CRM，以实现无缝的潜在客户管理和销售跟踪。从成功的支付中自动创建联系人和机会，让您的销售团队了解产生收入的活动。

<Info>
  此集成需要具有适当权限的 Close CRM API 密钥。
</Info>

## 开始使用

<Steps>
  <Step title="Open the Webhook Section">
    在您的 Dodo Payments 仪表板中，导航到 <b>Webhooks → + Add Endpoint</b>，并展开集成下拉菜单。

    <Frame>
      <img src="https://mintcdn.com/dodopayments/slbAEdrLLwKHfaRf/images/integrations/close-crm.png?fit=max&auto=format&n=slbAEdrLLwKHfaRf&q=85&s=bd462e078ea95d7853eb066cdbaebb0f" alt="Add Endpoint and integrations dropdown" style={{ maxHeight: '500px', width: 'auto' }} width="1710" height="948" data-path="images/integrations/close-crm.png" />
    </Frame>
  </Step>

  <Step title="Select Close CRM">
    选择 <b>Close CRM</b> 集成卡片。
  </Step>

  <Step title="Enter API Key">
    在配置中提供您的 Close CRM API 密钥。
  </Step>

  <Step title="Configure Transformation">
    编辑转换代码，将支付数据映射到 Close CRM 对象。
  </Step>

  <Step title="Test & Create">
    使用示例有效负载进行测试，然后点击 <b>创建</b> 以激活同步。
  </Step>

  <Step title="Done!">
    🎉 现在支付事件将自动在 Close CRM 中创建/更新记录。
  </Step>
</Steps>

## 转换代码示例

### 从支付创建联系人

```javascript create_contact.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://api.close.com/api/v1/contact/";
    webhook.payload = {
      name: p.customer.name,
      emails: [p.customer.email],
      phones: [p.customer.phone || ''],
      custom: {
        payment_amount: (p.total_amount / 100).toFixed(2),
        payment_method: p.payment_method || '',
        dodo_customer_id: p.customer.customer_id
      }
    };
  }
  return webhook;
}
```

### 从订阅创建机会

```javascript create_opportunity.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "subscription.active") {
    const s = webhook.payload.data;
    webhook.url = "https://api.close.com/api/v1/opportunity/";
    webhook.payload = {
      lead_id: s.customer.customer_id,
      value: (s.recurring_pre_tax_amount / 100).toFixed(2),
      value_period: s.payment_frequency_interval,
      title: `Subscription - ${s.product_id}`,
      custom: {
        subscription_id: s.subscription_id,
        billing_frequency: s.payment_frequency_interval,
        next_billing: s.next_billing_date
      }
    };
  }
  return webhook;
}
```

## 提示

* 使用 Close CRM 的 API 文档了解字段映射
* 包含用于支付特定数据的自定义字段
* 将订阅金额映射到机会值
* 使用客户 ID 进行正确的潜在客户关联

## 故障排除

<AccordionGroup>
  <Accordion title="Records not created in Close CRM">
    * 验证 API 密钥具有写入权限
    * 检查是否包含必填字段
    * 确保电子邮件格式有效
    * 检查 Close CRM API 速率限制
  </Accordion>

  <Accordion title="Transformation errors">
    * 验证 JSON 结构与 Close CRM API 格式匹配
    * 检查所有必填字段是否存在
    * 确保字段名称与 Close CRM 模式完全匹配
  </Accordion>
</AccordionGroup>
