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

# PHP SDK

> The official Loops PHP package.

[![Packagist Total Downloads](https://img.shields.io/packagist/dt/loops-so/loops?style=social)](https://packagist.org/packages/loops-so/loops)

## Installation

Install the package [using Composer](https://packagist.org/packages/loops-so/loops):

```bash theme={"dark"}
composer require loops-so/loops
```

<Tip>
  You can install [Loops skills](/skills) to help your coding agents use the Loops CLI, API and SDKs to create campaigns, manage contacts, send events, and send transactional emails.
</Tip>

You will need a Loops API key to use the SDK.

In your Loops account, go to the [API Settings page](https://app.loops.so/settings?page=api) and click **Generate key**.

Copy this key and save it in your application code (for example in an environment variable).

## Usage

```php theme={"dark"}
use Loops\LoopsClient;
use Loops\Exceptions\APIError;

$loops = new LoopsClient(env('LOOPS_API_KEY'));

try {
    $result = $loops->contacts->create('test@example.com', [
        'firstName' => 'John',
    ]);
} catch (APIError $e) {
    echo $e->getMessage();
    $returnedJson = $e->getJson();
    $statusCode = $e->getStatusCode();
}
```

Use `RateLimitExceededError` to handle rate limits. See the [SDK docs](https://packagist.org/packages/loops-so/loops) for every method, namespaces, and error handling.

See the API documentation to learn more about [rate limiting](/api-reference/intro#rate-limiting) and [error handling](/api-reference/intro#debugging).

<CardGroup>
  <Card title="Packagist" icon="php" href="https://packagist.org/packages/loops-so/loops">
    View the full documentation on Packagist.
  </Card>

  <Card title="GitHub" icon="github" href="https://github.com/Loops-so/loops-php">
    View the source code and release notes.
  </Card>

  <Card title="Loops API" icon="rectangle-terminal" href="/api-reference/intro">
    Read the Loops API reference.
  </Card>
</CardGroup>
