PHPackages                             thisdata/api - 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. thisdata/api

ActiveLibrary[API Development](/categories/api)

thisdata/api
============

PHP client for interacting with the ThisData API.

v0.2.0(9y ago)232.8k11MITPHPPHP &gt;=5.5.0

Since Jan 30Pushed 9y ago4 watchersCompare

[ Source](https://github.com/thisdata/thisdata-php)[ Packagist](https://packagist.org/packages/thisdata/api)[ RSS](/packages/thisdata-api/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (9)Used By (1)

ThisData API Client [![Build Status](https://camo.githubusercontent.com/f1fa6483363ec392508dce3d3eee1d8ddbf3fb6fa893708c03ae570e80479449/68747470733a2f2f7472617669732d63692e6f72672f74686973646174612f74686973646174612d7068702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/thisdata/thisdata-php)
==================================================================================================================================================================================================================================================================================================================

[](#thisdata-api-client-)

Consume the [ThisData.com](https://thisdata.com/) REST API using this client. Requires at least PHP5.5.

Install
-------

[](#install)

Using composer:

```
composer require thisdata/api

```

Quick Start
-----------

[](#quick-start)

Use the factory to return an instance of `ThisData\Api\ThisData`, configured with default settings.

```
use ThisData\Api\ThisData;

$apiKey = '';

$thisData = ThisData::create($apiKey);
```

> ⚠️ Don't commit your API key to source control! Use an environment variable, or perhaps you have a configuration solution that allows you to store secrets in local configuration without being shared.

Each endpoint will have different methods, depending on the functionality the endpoint provides. For instance, the events endpoint can track successful login attempts.

### API Documentation

[](#api-documentation)

Documentation for API endpoints can be found here:

- [POST Events](http://help.thisdata.com/docs/apiv1events)
- [POST Verify](http://help.thisdata.com/docs/apiv1verify)
- [GET Events](http://help.thisdata.com/docs/v1getevents)

### Tracking Events

[](#tracking-events)

Use the `$thisData` instance to get an instance of the events endpoint.

```
$endpoint = $thisData->getEventsEndpoint();
```

Then track events:

```
$ip = $_SERVER['REMOTE_ADDR'];
$user = [
    'id' => 'johntitor',
    'name' => 'John Titor',
    'email' => 'john.titor@thisdata.com',
    'mobile' => '+64270000001'
];
$userAgent = $_SERVER['HTTP_USER_AGENT'];

$endpoint->trackLogIn($ip, $user, $userAgent);

$verb = 'my-custom-verb';
$endpoint->trackEvent($verb, $ip, $user, $userAgent);
```

When the login attempt is unsuccessful:

```
$ip = $_SERVER['REMOTE_ADDR'];
$user = [
    'id' => 'johntitor',
    'authenticated' => false
];
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$endpoint->trackEvent(EventsEndpoint::VERB_LOG_IN_DENIED, $ip, $user, $userAgent);
```

When you're using a multi-tenanted app:

```
$ip = $_SERVER['REMOTE_ADDR'];
$user = [
    'id' => 'johntitor'
];
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$source = [
    'name' => 'SubCustomer 1'
]
$endpoint->trackLogIn($ip, $user, $userAgent, $source);
```

### Verifying a User

[](#verifying-a-user)

When a sensitive action is about to occur, perhaps before finalizing the log-in process, you can verify that the user is who they say they are, and check the risk that their account is being impersonated by an attacker. If they present a medium or high risk, force them to provide a two-factor authentication code.

```
$endpoint = $thisData->getVerifyEndpoint();

$ip = $_SERVER['REMOTE_ADDR'];
$user = [
    'id' => 'johntitor'
];
$userAgent = $_SERVER['HTTP_USER_AGENT'];

$response = $endpoint->verify($ip, $user, $userAgent);

if ($response['risk_level'] != "green") {
    # Ask for Two Factor Authentication code
} else {
    # Everything is OK
}
```

### Getting a list of Events (Audit Log)

[](#getting-a-list-of-events-audit-log)

You can fetch a paginated, filterable array of Events from the API. The method accepts any of the parameters described in the documentation:

e.g. returning the 10 most recent `log-in` events for a user

```
$endpoint = $thisData->getEventsEndpoint();
$events = $endpoint->getEvents(["verb" => "log-in", "user_id" => 112233, "limit" => 10]);
```

Advanced
--------

[](#advanced)

There are several configuration options that modify the way the library behaves. By using the Builder you can set these configuration options.

```
use ThisData\Api\Builder;
$builder = new Builder($apiKey);

// Configure the builder here. See below for more details.
// ...
// e.g. $builder->setAsync(false);
// $builder->setExpectJsCookie(true);
// ...

$thisData = $builder->build();
```

### Synchronous Requests

[](#synchronous-requests)

By default, requests are sent to the server asynchronously. If this is not required, or synchronous communication is preferred, configure your builder to use synchronous requests.

```
$builder->setAsync(false);
```

### ThisData's Javascript library

[](#thisdatas-javascript-library)

ThisData's Javascript tracking code is optional, but when included in a page will add a cookie called `__tdli`. If you're using the optional javascript library, this library will automatically pick up that cookie. You should also tell the API that each request *should* come with a cookie:

```
$builder->setExpectJsCookie(true);
```

### Network Configuration

[](#network-configuration)

If you require more control of your network settings, such as using a proxy, configure the client settings when building.

```
$builder->setClientOption('proxy', 'tcp://localhost:8125');
```

If you want to see the verbose output of the HTTP request, enable debug mode in Guzzle.

```
$builder->setClientOption('debug', true);
```

All settings supported by the [Guzzle HTTP Client](http://docs.guzzlephp.org/en/latest) can be configured here, including [curl options](http://docs.guzzlephp.org/en/latest/faq.html#how-can-i-add-custom-curl-options).

### Direct Access to the HTTP client

[](#direct-access-to-the-http-client)

If you require access to directly interact with the Guzzle HTTP client to send custom requests, the configured instance can be retrieved from an endpoint.

```
/** @var GuzzleHttp\Client $guzzle */
$guzzle = $events->getClient();
```

Alternatively, you can instantiate the client manually, without the added endpoint abstration layers.

```
$client = new ThisData\Api\Client(''); // An extension of the GuzzleHttp\Client class
$client->post('events', ['body' => '{"ip":"127.0.0.1"}']);
```

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

[](#contributing)

Thanks for helping! Start by forking the repository. Then make sure the tests pass:

```
composer install
./vendor/bin/phpunit

```

Make your changes, add test coverage, and check the tests are still passing. Then open a PR! :)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.7% of commits — single point of failure

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 ~90 days

Total

4

Last Release

3488d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/32586a062f5826a6d108252dfea725ec3ca8379b94099d3b24c3cb8245acc013?d=identicon)[thisdata](/maintainers/thisdata)

---

Top Contributors

[![emarref](https://avatars.githubusercontent.com/u/556594?v=4)](https://github.com/emarref "emarref (36 commits)")[![richet](https://avatars.githubusercontent.com/u/397207?v=4)](https://github.com/richet "richet (5 commits)")[![nickmalcolm](https://avatars.githubusercontent.com/u/342417?v=4)](https://github.com/nickmalcolm "nickmalcolm (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)
