# Connect KeyCRM

The agent finds a customer by phone and creates orders in your KeyCRM pipeline right during the conversation.

> Full REST + WebSocket API reference: https://api.happ.tools/reference

## What you need [#what-you-need]

* A KeyCRM account on a paid plan: the API is open on all paid plans.
* A pipeline and starting status for new orders.
* A Happ agent that talks to customers.

<Steps>
  <Step>
    ### Get the API key in KeyCRM [#get-the-api-key-in-keycrm]

    In KeyCRM open **Settings** → **General** → **API**. Click **Generate** if there is no key yet and copy it.

        <img alt="API key field in KeyCRM settings" src="__img0" />
  </Step>

  <Step>
    ### Connect KeyCRM in Happ [#connect-keycrm-in-happ]

    Open **Integrations**, find **KeyCRM** and click **Connect**. Paste the key, tick the data sync consent and click **Connect**.
  </Step>

  <Step>
    ### Choose what the agent may do [#choose-what-the-agent-may-do]

    Open the settings on the KeyCRM card. **Search**: the agent looks up customers by phone. **Create**: pick the mode (pipeline card or order), the pipeline, status and source.
  </Step>

  <Step>
    ### Turn on calls on CRM events (optional) [#turn-on-calls-on-crm-events-optional]

    In the KeyCRM card menu choose **Calls on CRM events**. Paste the Happ link into KeyCRM webhooks and set a trigger, for example "new order → confirmation call".
  </Step>
</Steps>

## Troubleshooting [#troubleshooting]

| Error                 | What to do                                                                                                |
| --------------------- | --------------------------------------------------------------------------------------------------------- |
| `INVALID_API_KEY`     | Copy the key from KeyCRM again without spaces and make sure it was generated.                             |
| `TOKEN_REVOKED` (401) | The key was regenerated. Create a new one and reconnect.                                                  |
| Orders do not arrive  | Check pipeline and status in settings, and the KeyCRM IP whitelist: empty or containing the Happ address. |

## Next [#next]

* [KeyCRM](/docs/integrations/crm/keycrm): all fields and disconnecting.
* [Test cases](/guides/tests): check the agent creates orders correctly, with tool mocks.
