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

# WhatsApp Instance and QR Code API in Go

> Create WhatsApp instances, connect numbers with a QR code, and manage multiple WhatsApp numbers from Golang with the Hypersender Enterprise API.

## Overview

Enterprise accounts can run multiple WhatsApp numbers and manage them through the API: create an instance for each number, connect it with a QR code, and monitor or restart it. These methods live under `client.Enterprise`. [(learn more about the Enterprise API)](https://docs.hypersender.com/v2/api-reference/enterprise/enterprise-whatsapp-api-introduction.md)

Unlike the other clients, Enterprise methods work across all your instances, so you pass the instance ID on each call instead of setting it in your environment.

Set your Enterprise API key in your `.env` file (or pass it with `hypersender.WithEnterprise(apiKey)`):

```bash theme={null}
HYPERSENDER_ENTERPRISE_API_KEY=
```

The examples assume `ctx` is a `context.Context`, such as `context.Background()`.

## List Instances

List the WhatsApp instances on your account, optionally filtered. [(learn more)](https://docs.hypersender.com/v2/api-reference/enterprise/instance-management/list-instances.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> instances, err := client.Enterprise.ListInstances(ctx, &hypersender.ListInstancesOptions{Status: "WORKING"})
> if err != nil {
>     log.Fatal(err)
> }
>
> fmt.Println(len(instances))
> ```

> [tab] Parameters
>
> `opts` is optional; pass `nil` to list all instances. Each field is sent as `filter[field]`.
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | opts.UUID | string | no | Filter by instance UUID |
> | opts.Name | string | no | Filter by name (partial match) |
> | opts.Phone | string | no | Filter by phone number |
> | opts.Status | string | no | `STOPPED`, `STARTING`, `WORKING`, `SCAN_QR_CODE`, `FAILED`, or `PENDING` |

## Create an Instance

Create a new WhatsApp instance. The response includes a QR code to scan with the phone. [(learn more)](https://docs.hypersender.com/v2/api-reference/enterprise/instance-management/create-instance.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> instance, err := client.Enterprise.CreateInstance(ctx, "+201234567890", "Support line",
>     &hypersender.CreateInstanceOptions{WebhookURL: "https://yourdomain.com/webhooks/whatsapp"})
> if err != nil {
>     log.Fatal(err)
> }
>
> fmt.Println(instance["id"], instance["qr_code"])
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | phone | string | yes | Phone number in E.164 format, e.g. `+201234567890` |
> | name | string | yes | Instance name, max 50 characters, unique on your account |
> | opts.WebhookURL | string | no | An `https` URL to receive this instance's webhooks |

## Check Instance Health

Check whether an instance is connected and working. [(learn more)](https://docs.hypersender.com/v2/api-reference/enterprise/instance-management/check-instance-health.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> health, err := client.Enterprise.GetInstanceHealth(ctx, "fa3d01c4-1234-4c0d-a12f-df319b612f8c")
> if err != nil {
>     log.Fatal(err)
> }
>
> fmt.Println(health)
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | instanceID | string | yes | The instance UUID |

## Request a New QR Code

Get a fresh WhatsApp QR code when the previous one expired or the phone was disconnected. [(learn more)](https://docs.hypersender.com/v2/api-reference/enterprise/instance-management/request-new-qr-code.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> res, err := client.Enterprise.RequestNewQRCode(ctx, "fa3d01c4-1234-4c0d-a12f-df319b612f8c")
> if err != nil {
>     log.Fatal(err)
> }
>
> qrCode, _ := res["qr_code"].(string)
>
> fmt.Println(qrCode)
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | instanceID | string | yes | The instance UUID |

## Restart an Instance

Restart an instance that is stuck or not responding. [(learn more)](https://docs.hypersender.com/v2/api-reference/enterprise/instance-management/restart-instance.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> if _, err := client.Enterprise.RestartInstance(ctx, "fa3d01c4-1234-4c0d-a12f-df319b612f8c"); err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | instanceID | string | yes | The instance UUID |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.