> ## 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]
>
> Want your coding agent to help with Loops? Install the Loops CLI and
> [skills](https://loops.so/docs/skills.md) with one command:
>
> ```bash theme={"dark"}
> curl -fsSL https://install.loops.so/wizard | sh
> ```

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](https://loops.so/docs/api-reference/intro.md#rate-limiting) and [error handling](https://loops.so/docs/api-reference/intro.md#debugging).

> [card] [Packagist](https://packagist.org/packages/loops-so/loops)
>
> View the full documentation on Packagist.

> [card] [GitHub](https://github.com/loops-so/loops-php)
>
> View the source code and release notes.

> [card] [Loops API](https://loops.so/docs/api-reference/intro.md)
>
> Read the Loops API reference.


## Related topics

- [Loops SDKs](https://loops.so/docs/sdks.md)
- [API Introduction](https://loops.so/docs/api-reference/intro.md)
- [Go SDK](https://loops.so/docs/sdks/go.md)
- [Ruby SDK](https://loops.so/docs/sdks/ruby.md)
- [JavaScript SDK](https://loops.so/docs/sdks/javascript.md)
