PHPackages                             delighted/delighted - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. delighted/delighted

AbandonedArchivedLibrary[API Development](/categories/api)

delighted/delighted
===================

Delighted PHP API Client

v4.2.0(2mo ago)51.6M—7.7%8[2 issues](https://github.com/delighted/delighted-php/issues)MITPHPPHP &gt;=7.1CI failing

Since Mar 5Pushed 2mo ago13 watchersCompare

[ Source](https://github.com/delighted/delighted-php)[ Packagist](https://packagist.org/packages/delighted/delighted)[ Docs](http://github.com/delighted/delighted-php)[ RSS](/packages/delighted-delighted/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (20)Used By (0)

> **DEPRECATION NOTICE:** Delighted is being sunset on June 30, 2026. This package is deprecated and will no longer be maintained or receive updates. For more information, visit the [Delighted Sunset FAQ](https://help.delighted.com/article/840-delighted-sunset-faq).

---

[![Build Status](https://camo.githubusercontent.com/9b22df8bc7a1d635a4fc6372d8bbdc3d7fcb8b569f072eb631ceddf511701ced/68747470733a2f2f7472617669732d63692e6f72672f64656c6967687465642f64656c6967687465642d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/delighted/delighted-php)

Delighted PHP API Client
========================

[](#delighted-php-api-client)

Official PHP client for the [Delighted API](https://delighted.com/docs/api).

Requirements
------------

[](#requirements)

- PHP 7.1 or greater
- The [Composer](http://getcomposer.org/) package manager
- A [Delighted API](https://delighted.com/docs/api) key

Installation
------------

[](#installation)

Install via [Composer](http://getcomposer.org/) by adding this to your `composer.json`:

```
{
  "require": {
    "delighted/delighted": "4.*"
  }
}

```

Then install via:

```
composer install

```

This will also install the [Guzzle](https://github.com/guzzle/guzzle) HTTP request library that the Delighted PHP API Client depends upon.

Configuration
-------------

[](#configuration)

To get started, you need to configure the client with your secret API key. At some point in your application's initialization, before you call any other Delighted PHP API client methods, do this (replacing `YOUR_API_KEY` with your actual API key, of course):

```
Delighted\Client::setApiKey('YOUR_API_KEY');

```

**Note:** Your API key is secret, and you should treat it like a password. You can find your API key in your Delighted account, under *Settings* &gt; *API*.

Usage
-----

[](#usage)

Adding/updating people and scheduling surveys:

```
// Add a new person, and schedule a survey immediately
$person1 = \Delighted\Person::create(['email' => 'ellie@icloud.com']);

// Add a new person, and schedule a survey after 1 minute (60 seconds)
$person2 = \Delighted\Person::create(['email' => 'richard.nguyen@aol.com', 'delay' => 60]);

// Add a new person, but do not schedule a survey
$person3 = \Delighted\Person::create(['email' => 'gvargas@gmail.com', 'send' => false]);

// Add a new person with full set of attributes, including a custom question
// product name, and schedule a survey with a 30 second delay
$props = ['customer_id' => 123, 'country' => 'USA', 'question_product_name' => 'The London Trench'];
$person4 = \Delighted\Person::create([
                                        'email' => 'alexis_burke@austinstephens.com',
                                        'name' => 'Alexis Burke',
                                        'properties' => $props,
                                        'delay' => 30
                                    ]);

// Update an existing person (identified by email), adding a name, without
// scheduling a survey
$updated_person1 = \Delighted\Person::create([
                                                'email' => 'ellie@icloud.com',
                                                'name' => 'Ellie Newman',
                                                'send' => false
                                            ]);
```

Unsubscribing people:

```
// Unsubscribe an existing person
\Delighted\Unsubscribe::create(['person_email' => 'ellie@icloud.com'])
```

Listing people:

```
// List all people, auto pagination
// Note: Make sure to handle the possible rate limits error
$people = \Delighted\Person::list();
while (true) {
  try {
    foreach ($people->autoPagingIterator() as $person) {
      // Do something with $person
    }
    break;
  } catch (\Delighted\RateLimitedException $e) {
    // Indicates how long (in seconds) to wait before making this request again
    $e->getRetryAfter();
    continue;
  }
}

// For convenience, this method can use a sleep to automatically handle rate limits
$people = \Delighted\Person::list();
foreach ($people->autoPagingIterator(['auto_handle_rate_limits' => true]) as $person) {
  // Do something with $person
}
```

Listing unsubscribed people:

```
// List all unsubscribed people, 20 per page, first 2 pages
$unsubscribes = \Delighted\Unsubscribe::all()
$unsubscribes_p2 = \Delighted\Unsubscribe::all(['page' => 2]);
```

Listing bounced people:

```
// List all bounced people, 20 per page, first 2 pages
$bounces = \Delighted\Bounce::all()
$bounces_p2 = \Delighted\Bounce::all(['page' => 2]);
```

Deleting a person and all of the data associated with them:

```
// Delete by person id
\Delighted\Person::delete(array('id' => 42));
// Delete by email address
\Delighted\Person::delete(array('email' => 'test@example.com'));
// Delete by phone number (must be E.164 format)
\Delighted\Person::delete(array('phone_number' => '+14155551212'));
```

Deleting pending survey requests

```
// Delete all pending (scheduled but unsent) survey requests for a person,
// by email.
\Delighted\SurveyRequest::deletePending(['person_email' => 'ellie@icloud.com']);
```

Adding survey responses:

```
// Add a survey response, score only
$survey_response1 = \Delighted\SurveyResponse::create(['person' => $person1->id, 'score' => 10]);

// Add *another* survey response (for the same person), score and comment
$survey_response2 = \Delighted\SurveyResponse::create([
                                                         'person' => $person1->id,
                                                         'score' => 5,
                                                         'comment' => 'Really nice.'
                                                      ]);
```

Retrieving a survey response:

```
// Retrieve an existing survey response
$survey_response3 = \Delighted\SurveyResponse::retrieve('123');
```

Updating survey responses:

```
// Update a survey response score
$survey_response4 = \Delighted\SurveyResponse::retrieve('234');
$survey_response4->score = 10;
$survey_response4->save();

// Update (or add) survey response properties
$survey_response4->person_properties = ['segment' => 'Online'];
$survey_response4->save();

// Update person who recorded the survey response
$survey_response4->person = '321';
$survey_response4->save();
```

Listing survey responses:

```
// List all survey responses, 20 per page, first 2 pages
$responses_p1 = \Delighted\SurveyResponse::all()
$responses_p2 = \Delighted\SurveyResponse::all(['page' => 2]);

// List all survey responses, 20 per page, expanding person object
$responses_p1_expand = \Delighted\SurveyResponse::all(['expand' => ['person']]);
// The person property is a \Delighted\Person object now
print $responses_p1_expand[0]->person->name;

// List all survey responses, 20 per page, for a specific trend (ID: 123)
$responses_p1_trend = \Delighted\SurveyResponse::all(['trend' => '123']);

// List all survey responses, 20 per page, in reverse chronological order
// (newest first)
$responses_p1_desc = \Delighted\SurveyResponse::all(['order' => 'desc']);

// List all survey responses, 100 per page, page 5, with a time range
$filtered_survey_responses = \Delighted\SurveyResponse::all([
                                                               'page' => 5,
                                                               'per_page' => 100,
                                                               'since' => gmmktime(0, 0, 0, 10, 1, 2013),
                                                               'until' => gmmktime(0, 0, 0, 11, 1, 2013)
                                                            ]);
```

Retrieving metrics:

```
// Get current metrics, 30-day simple moving average, from most recent response
$metrics = \Delighted\Metrics::retrieve()

// Get current metrics, 30-day simple moving average, from most recent response
// for a specific trend (ID: 123)
$metrics = \Delighted\Metrics::retrieve(['trend' => '123']);

// Get metrics, for given range
$metrics = \Delighted\Metrics::retrieve([
                                           'since' => gmmktime(0, 0, 0, 10, 1, 2013),
                                           'until' => gmmktime(0, 0, 0, 11, 1, 2013)
                                        ]);
```

Managing Autopilot:

```
// Get Autopilot configuration for the `email` platform
$autopilot = \Delighted\AutopilotConfiguration::retrieve('email');

// List people in AutopilotMembership for the `email` platform
$people_autopilot = \Delighted\AutopilotMembership\Email::list();
foreach ($people_autopilot->autoPagingIterator(['auto_handle_rate_limits' => true]) as $person_autopilot) {
  // Do something with $person_autopilot
}

// Add people to AutopilotMembership
$autopilot = \Delighted\AutopilotMembership\Email::create(['person_email' => 'test@example.com']);

// Add people to AutopilotMembership, with a full set of attributes
$props = ['customer_id' => 123, 'country' => 'USA', 'question_product_name' => 'The London Trench'];
$autopilot = \Delighted\AutopilotMembership\Sms::create(['person_phone_number' => '+14155551212', 'properties' => $props]);

// Delete by person id
\Delighted\AutopilotMembership\Email::delete(['person_id' => 42]);

// Delete by email address
\Delighted\AutopilotMembership\Email::delete(['person_email' => 'test@example.com']);

// Delete by phone number (must be E.164 format)
\Delighted\AutopilotMembership\Sms::delete(['person_phone_number' => '+14155551212']);
```

Rate limits
-----------

[](#rate-limits)

If a request is rate limited, a `\Delighted\RateLimitedException` exception is raised. You can rescue that exception to implement exponential backoff or retry strategies. The exception provides a `getRetryAfter()` method to tell you how many seconds you should wait before retrying. For example:

```
try {
    $metrics = \Delighted\Metrics::retrieve();
} catch (Delighted\RateLimitedException $e) {
    $errorCode = $e->getCode();

    if ($errorCode == 429) { // rate limited
        $retryAfterSeconds = e->getRetryAfter();
        // wait for $retryAfterSeconds before retrying
        // add your retry strategy here ...
    } else {
        // some other error
    }
}
```

Advanced Configuration and Testing
----------------------------------

[](#advanced-configuration-and-testing)

The various Delighted resource methods use a shared client object to make the HTTP requests to the Delighted server. To change how that shared client object works, you can pass an array of options to the `\Delighted\Client::getInstance()` method (before you call any resource methods) that control its behavior.

The chief option you may want to change is `baseUrl`, which defaults to `https://api.delighted.com/v1/`. If you want to send Delighted API requests to a different URL (for example, a local mock server for testing), pass that URL as the value for the `baseURL` array key in the options passed to `\Delighted\Client::getInstance()`. For example:

```
$myUrl = 'http://localhost/delighted-mock/';
\Delighted\Client::getInstance(['baseUrl' => $myUrl]);
```

You can also easily mock Delighted API requests and responses by following the pattern that the API client's test cases use:

- Use the `\Delighted\TestClient` class instead of `Delighted\Client`
- Create a `\GuzzleHttp\Handler\MockHandler` to mock the requests. Because the `$client` is a shared instance, you'll want to use a shared `$mock_handler`, too.
- Create `\GuzzleHttp\HandlerStack` and pass to the client.
- Make assertions about the request and response as desired.

For example:

```
$mock_response = new \GuzzleHttp\Psr7\Response(200, [], ['nps' => 10]);
$mock_handler = new \GuzzleHttp\Handler\MockHandler([$mock_response]);
$handler_stack = \GuzzleHttp\HandlerStack::create($mock_handler);
$client = \Delighted\TestClient::getInstance(['apiKey' => 'xyzzy', 'handler' => $handler_stack]);
$metrics = Delighted\Metrics::retrieve([], $client);

// This prints 10 -- the value comes from the mock response
print $metrics->nps;
```

Contributing
------------

[](#contributing)

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Run the tests (`php -f run-tests.php`)
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create new Pull Request

Releasing
---------

[](#releasing)

1. Bump the version in `lib/Delighted/Version.php`.
2. Update the README and CHANGELOG as needed.
3. Tag the commit for release.
4. Push (Packagist will pick up the release from the tag).

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance79

Regular maintenance activity

Popularity47

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~251 days

Recently: every ~546 days

Total

17

Last Release

67d ago

Major Versions

v1.2.0-beta.1 → v2.0.0-beta2017-03-14

v2.2.0 → v3.0.02019-06-13

v3.0.0 → v4.0.0-rc12020-03-18

PHP version history (3 changes)v1.0.0-betaPHP &gt;= 5.3.3

v2.0.0-betaPHP &gt;=5.5

v3.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/c6dc789fd8a5ef7cca8f6d4f69a9bf75f3bd656670891f6769e923ac7cb66df7?d=identicon)[erikpilz](/maintainers/erikpilz)

![](https://www.gravatar.com/avatar/14f7a64aaf56ea51ba7c0a3151c2a1541f5a3d530e66dad17e7fb5037a80a77a?d=identicon)[jloyolask8](/maintainers/jloyolask8)

![](https://www.gravatar.com/avatar/33075f79e73c792f2b7748d482a4916c58b9e6835e0f8b9050ba8839ee3517f9?d=identicon)[mpedroso98](/maintainers/mpedroso98)

![](https://www.gravatar.com/avatar/a01dc0649352ac9d1222719f4d4306c7125f473a571884865b32a33219c6cd68?d=identicon)[bromney1](/maintainers/bromney1)

![](https://avatars.githubusercontent.com/u/214547722?v=4)[Jacob Flores](/maintainers/jflores-q)[@jflores-q](https://github.com/jflores-q)

---

Top Contributors

[![akalongman](https://avatars.githubusercontent.com/u/423050?v=4)](https://github.com/akalongman "akalongman (27 commits)")[![mkdynamic](https://avatars.githubusercontent.com/u/4312?v=4)](https://github.com/mkdynamic "mkdynamic (24 commits)")[![kindjar](https://avatars.githubusercontent.com/u/290336?v=4)](https://github.com/kindjar "kindjar (21 commits)")[![thierryung](https://avatars.githubusercontent.com/u/5083899?v=4)](https://github.com/thierryung "thierryung (16 commits)")[![davidsklar](https://avatars.githubusercontent.com/u/177495?v=4)](https://github.com/davidsklar "davidsklar (12 commits)")[![erikpilz](https://avatars.githubusercontent.com/u/825804?v=4)](https://github.com/erikpilz "erikpilz (4 commits)")[![jflores-q](https://avatars.githubusercontent.com/u/214547722?v=4)](https://github.com/jflores-q "jflores-q (3 commits)")[![rnewton](https://avatars.githubusercontent.com/u/445976?v=4)](https://github.com/rnewton "rnewton (2 commits)")[![salbertson](https://avatars.githubusercontent.com/u/154463?v=4)](https://github.com/salbertson "salbertson (2 commits)")[![geoff-parsons](https://avatars.githubusercontent.com/u/9072?v=4)](https://github.com/geoff-parsons "geoff-parsons (2 commits)")[![baohx2000](https://avatars.githubusercontent.com/u/486322?v=4)](https://github.com/baohx2000 "baohx2000 (1 commits)")[![cmgmyr](https://avatars.githubusercontent.com/u/4693481?v=4)](https://github.com/cmgmyr "cmgmyr (1 commits)")[![mlteal](https://avatars.githubusercontent.com/u/3302175?v=4)](https://github.com/mlteal "mlteal (1 commits)")

---

Tags

delighted

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/delighted-delighted/health.svg)

```
[![Health](https://phpackages.com/badges/delighted-delighted/health.svg)](https://phpackages.com/packages/delighted-delighted)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
