PHPackages                             c14r/directus-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. [HTTP &amp; Networking](/categories/http)
4. /
5. c14r/directus-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

c14r/directus-api
=================

A Wrapper for the Directus REST-API

v1.0.5(5y ago)93797[4 issues](https://github.com/C14r/directus-api/issues)1GPL-3.0-onlyPHPPHP ^7.3CI failing

Since Aug 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/C14r/directus-api)[ Packagist](https://packagist.org/packages/c14r/directus-api)[ Docs](http://www.christian-pfeifer.de/)[ RSS](/packages/c14r-directus-api/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (2)Versions (9)Used By (1)

Directus API Wrapper for PHP
============================

[](#directus-api-wrapper-for-php)

[![packagist version](https://camo.githubusercontent.com/e24d1cc80b2efc99c9bb2373b0ba10d249e711e4d4b6a2686eeb1d45b0c99e51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f633134722f64697265637475732d617069)](https://camo.githubusercontent.com/e24d1cc80b2efc99c9bb2373b0ba10d249e711e4d4b6a2686eeb1d45b0c99e51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f633134722f64697265637475732d617069)[![directus version](https://camo.githubusercontent.com/90d8b36170b76fba146d84bb7a18c894d374903d3af9fee3698a385088d174c5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64697265637475732d76382e382e312d626c7565)](https://camo.githubusercontent.com/90d8b36170b76fba146d84bb7a18c894d374903d3af9fee3698a385088d174c5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64697265637475732d76382e382e312d626c7565)

This package allows users to easily consume the REST API provided by the Directus Headless CMS system in any PHP app.

Installing
----------

[](#installing)

The recommended way to install Directus-API is through [Composer](https://getcomposer.org/).

```
composer require c14r/directus-api
```

Table of Content
----------------

[](#table-of-content)

- [Directus API Wrapper for PHP](#directus-api-wrapper-for-php)
    - [Installing](#installing)
    - [Table of Content](#table-of-content)
- [Usage](#usage)
    - [Creating an API-instance](#creating-an-api-instance)
    - [Authentification](#authentification)
    - [Error handling](#error-handling)
    - [Items](#items)
    - [Files](#files)
    - [Assets (Thumbnails)](#assets-thumbnails)
    - [Activities](#activities)
    - [Collections](#collections)
    - [Collection Presets](#collection-presets)
    - [Extensions](#extensions)
    - [Fields](#fields)
    - [Folders](#folders)
    - [Mail](#mail)
    - [Permissions](#permissions)
    - [Projects](#projects)
    - [Relations](#relations)
    - [Revisions](#revisions)
    - [Roles](#roles)
    - [SCIM](#scim)
    - [Server](#server)
    - [Settings](#settings)
    - [Users](#users)
    - [Utilities](#utilities)
    - [Custom](#custom)

Usage
=====

[](#usage)

Creating an API-instance
------------------------

[](#creating-an-api-instance)

```
use C14r\Directus\API;

$api = new API('http://example.com/api/', 'v1'); // base Url and project
```

Authentification
----------------

[](#authentification)

```
// Retrieve a Temporary Access Token
$api->authenticate('username', '********');

// Using Static token
$api->token('ThIs_Is_ThE_tOkEn');
```

Error handling
--------------

[](#error-handling)

```
$items = $api->items($collection)->get();

if($api->isError($items)) {
    // The request failed.
}
```

Items
-----

[](#items)

```
// List the Items
$items = $api->items($collection)->get();

// Retrieve an Item
$item = $api->item($collection, $id)->get();

// Create an Item
$api->items($collection)->create([
    'title' => 'The Title!',
    'status' => 'draft'
]);

// Update an Item
$api->item($collection, $id)->update([
    'title' => 'The new Title!'
]);

// Delete an Item
$api->item($collection, $id)->delete();

// List Item Revisions
$revisions = $api->itemRevisions($collection, $id)->get();

// Retrieve an Item Revision
$revision = $api->itemRevision($collection, $id, $offset)->get();

// Revert to a Given Revision
$api->itemRevert($collection, $id, $revision)->update();
```

Files
-----

[](#files)

```
// List the files.
$files = $api->files()->get();

// Retrieve a File
$file = $api->file($id)->get();

// Create a File
$api->files()->create([
    'data' => base64_encode(file_get_contents('./file.pdf'))
]);

// Update a File
$api->file(1)->update([
    'data' => base64_encode(file_get_contents('./file.pdf'))
]);

// Delete a File
$api->file(1)->delete();
```

Assets (Thumbnails)
-------------------

[](#assets-thumbnails)

```
// Get an asset
$asset = $api->asset($private_hash)->get();

// or using key, w, h, f, q
$asset = $api->asset($private_hash)->queries([
    'key' => $key,
    'w' => 100,
    'h' => 100,
    'f' => 'crop',
    'q' => 80
])->get();
```

Activities
----------

[](#activities)

```
// List Activity Actions
$activities = $api->activities()->get();

// Retrieve an Activity Action
$activity = $api->activity($id)->get();

// Create a Comment
$api->comments()->create([
    'collection' => $collection,
    'id' => $id,
    'comment' => 'The body of the comment.'
]);

// Update a Comment
$api->comment($id)->update([
    'comment' => 'The new body of the comment.'
]);

// Delete a Comment
$api->comment($id)->delete();
```

Collections
-----------

[](#collections)

```
// List Collections
$collections = $api->collections()->get();

// Retrieve a Collection
$collection = $api->collection($collection)->get();

// Create a Collection
$api->collections()->create([
    'collection' => 'my_collection',
    'fields' => [
        [
            'field' => 'id',
            'type' => 'integer',
            'datatype' => 'int',
            'length' => 11,
            'interface' => 'numeric',
            'primary_key' => true
        ]
    ]
]);

// Update a Collection
$collection = $api->collection($collection)->update([
    'note' => 'This is my first collection'
]);

// Delete a Collection
$collection = $api->collection($collection)->delete();
```

Collection Presets
------------------

[](#collection-presets)

```
// List the Collection Presets
$presets = $api->presets()->get();

// Retrieve a Collection Preset
$preset = $api->preset($id)->get();

// Create a Collection Preset
$api->presets()->create([
    'collection' => $collection,
    'title' => 'Title'
    // ...
]);

// Update a Collection Preset
$api->preset($id)->update([
    'collection' => $collection,
    'title' => 'New Title'
]);

// Delete a Collection Preset
$api->preset($id)->delete();
```

Extensions
----------

[](#extensions)

```
// List Interfaces
$interfaces = $api->interfaces()->get();

// List Layouts
$layouts = $api->layouts()->get();

// List Modules
$modules = $api->modules()->get();
```

Fields
------

[](#fields)

```
// List Fields
$fields = $api->fields()->get();

// List Fields in Collection
$fields = $api->fields($collection)->get();

// Retrieve a Field
$field = $api->field($collection, $field)->get();

// Create a Field
$api->fields($collection)->create([
    'field' => 'test',
    'type' => 'string',
    'datatype' => 'VARCHAR',
    'length' => 255,
    'interface' => 'text-input'
]);

// Update a Field
$api->field($collection, $field)->update([
    'note' => 'Enter the title here.'
]);

// Delete a Field
$api->field($collection, $field)->delete();
```

Folders
-------

[](#folders)

```
// List the Folders
$folders = $api->folders()->get();

// Retrieve a Folder
$folder = $api->folder($id)->get();

// Create a Folder
$api->folders()->create([
    'name' => 'Amsterdam'
]);

// Update a Folder
$api->folder($id)->update([
    'parent_folder' => 3
]);

// Delete a Folder
$api->folder($id)->delete();
```

Mail
----

[](#mail)

```
// Send an Email
$api->mail()->create([
    'to' => [
        'user@example.com',
        'admin@example.com'
    ],
    'subject' => 'New Password',
    'body' => 'Hello {{name}}, this is your new password: {{password}}.',
    'type' => 'html',
    'data' => [
        'name' => 'John Doe',
        'password' => 'secret'
    ]
]);
```

Permissions
-----------

[](#permissions)

```
// List the Permissions
$permissions = $api->permissions()->get();

// Retrieve a Permission
$permission = $api->permission($id)->get();

// List the Current User's Permissions
$permissions = $api->myPermissions()->get();

// List the Current User's Permissions for Given Collection
$permission = $api->myPermission($collection)->get();

// Create a Permission
$api->permissions()->create([
    'collection' => 'customers',
    'role' => 3,
    'read' => 'mine',
    'read_field_blacklist' => ['featured_image']
]);

// Update a Permission
$api->permission($id)->update([
    'read' => 'full'
]);

// Delete a Permission
$api->permission($id)->delete();
```

Projects
--------

[](#projects)

```
// List Available Projects
$projects = $api->projects()->get();

// Retrieve Project Info
$project = $api->project($project)->get();

// Create a Project
$api->projects()->create([
    'project' => 'thumper',
    'super_admin_token' => 'very_secret_token',
    'db_name' => 'db',
    'db_user' => 'root',
    'db_password' => 'root',
    'user_email' => 'admin@example.com',
    'user_password' => 'password'
]);

// Delete a Project
$api->projects($project)->delete(); // There should be no s in 'projects', but unfortunately it has to be there because of the different endpoints :(
```

Relations
---------

[](#relations)

```
// List the Relations
$relations = $api->relations()->get();

// Retrieve a Relation
$relation = $api->relation($id)->get();

// Create a Relation
$api->relations()->create([
    'collection_many' => 'articles',
    'field_many' => 'author',
    'collection_one' => 'authors',
    'field_one' => 'books'
]);

// Update a Relation
$api->relation($id)->update([
    'field_one' => 'books'
]);

//  Delete a Relation
$api->relation($id)->delete();
```

Revisions
---------

[](#revisions)

```
// List the Revisions
$revisions = $api->revisions()->get();

// Retrieve a Revision
$revision = $api->revision($id)->get();
```

Roles
-----

[](#roles)

```
// List the Roles
$roles = $api->roles()->get();

// Retrieve a Role
$role = $api->role($id)->get();

// Create a Role
$api->roles()->create([
    'name' => 'Interns'
]);

// Update a Role
$api->role($id)->update([
    'description' => 'Limited access only.'
]);

// Delete a Role
$api->role($id)->delete();
```

SCIM
----

[](#scim)

```
//  List SCIM Users
$users = $api->scimUsers()->get();

// Retrieve a SCIM User
$user = $api->scimUser($external_id)->get();

//  Create a SCIM User
$api->scimUsers()->create([
    'schemas' => [
        'urn:ietf:params:scim:schemas:core:2.0:User'
    ],
    'userName' => 'johndoe@example.com',
    'externalId' => 'johndoe-id',
    'name' => [
        'familyName' => 'Doe',
        'givenName' => 'John'
    ]
]);

// Update a SCIM User
$api->scimUser($external_id)->update([
    'schemas' => [
        'urn:ietf:params:scim:schemas:core:2.0:User'
    ],
    'name' => [
        'familyName' => 'Doe',
        'givenName' => 'Johnathan'
    ]
]);

// Delete a SCIM User
$api->scimUser($external_id)->delete();

// List the SCIM Groups
$groups = $api->scimGroups()->get();

//  Retrieve a SCIM Group
$group = $api->scimGroup($id)->get();

// Create a SCIM Group
$api->scimGroups()->create([
    'schemas' => [
        'urn:ietf:params:scim:schemas:core:2.0:Group'
    ],
    'displayName' => 'Editors',
    'externalId' => 'editors-id'
]);

//  Update a SCIM Group
$api->scimGroup($id)->update([
    'schemas' => [
        'urn:ietf:params:scim:schemas:core:2.0:Group'
    ],
    'displayName' => 'Writers'
]);

// Delete a SCIM Group
$api->scimGroup($id)->delete();
```

Server
------

[](#server)

```
// Retrieve Server Info
$info = $api->info($super_admin_token)->get();

//  Ping the server
$pong = $api->ping()->get();
```

Settings
--------

[](#settings)

```
// List the Settings
$settings = $api->settings()->get();

// Retrieve a Setting
$setting = $api->setting($id)->get();

// Create a Setting
$api->settings()->create([
    'key' => 'my_custom_setting',
    // 'value' => 12
]);

// Update a Setting
$api->setting($id)->update([
    'value' => 15
]);

//  Delete a Setting
$api->setting($id)->delete();
```

Users
-----

[](#users)

```
// List the users
$users = $api->users()->get();

// Retrieve a User
$user = $api->user($id)->get();

// Retrieve the Current User
$me = $api->me()->get();

// Create a User
$api->users()->create([
    'first_name' => 'Ben',
    'last_name' => 'Haynes',
    'email' => 'demo@example.com',
    'password' => 'd1r3ctu5',
    'role' => 3,
    'status' => 'active'
]);

// Update a User
$api->user($id)->update([
    'status' => 'suspended'
]);

// Delete a User
$api->user($id)->delete();

// Invite a New User
$api->invite('demo@example.com')->create();

//  Accept User Invite
$api->acceptUser($token)->post();

// Track the Last Used Page
$api->trackingPage($id, '/thumper/settings/')->update();

// List User Revisions
$revisions = $api->userRevisions($id)->get();

// Retrieve a User Revision
$revision = $api->userRevision($id, $offset)->get();
```

Utilities
---------

[](#utilities)

```
// Create a Hash
$hash = $api->hash('Directus')->create();

// Verify a Hashed String
$valid = $api->hashMatch('Directus', $hash)->create();

// Generate a Random String
$string = $api->randomString($length)->create();

// Generate a 2FA Secret
$secret = $api->secret()->get();
```

Custom
------

[](#custom)

```
// Custom GET-Requests
$response = $api->custom('example')->get();

// Custom POST-Requests
$response = $api->custom('example')->post(); // or ->create()

// Custom PATCH-Requests
$response = $api->custom('example')->patch(); // or ->update()

// Custom DELETE-Requests
$response = $api->custom('example')->delete();

// Request with parameters
$response = $api->custom('example/:id', ['id' => $id])->get();
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance11

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.3% 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 ~11 days

Total

6

Last Release

2037d ago

### Community

Maintainers

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

---

Top Contributors

[![C14r](https://avatars.githubusercontent.com/u/567569?v=4)](https://github.com/C14r "C14r (17 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![kdelnogal](https://avatars.githubusercontent.com/u/12181550?v=4)](https://github.com/kdelnogal "kdelnogal (1 commits)")[![klodoma](https://avatars.githubusercontent.com/u/944350?v=4)](https://github.com/klodoma "klodoma (1 commits)")[![mglinski](https://avatars.githubusercontent.com/u/78872?v=4)](https://github.com/mglinski "mglinski (1 commits)")

---

Tags

directusdirectus-apihttpclientresthttp clientwrapperdirectus

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[slimpay/hapiclient

An HTTP Client using HAL as the format for resources.

14317.3k](/packages/slimpay-hapiclient)[zoonman/pixabay-php-api

PixabayClient is a PHP HTTP client library to access Pixabay's API

3354.7k](/packages/zoonman-pixabay-php-api)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11259.2k](/packages/e-moe-guzzle6-bundle)[opgg/riotquest

RiotQuest, PHP RiotAPI client library that focused on multi request from OP.GG

172.6k](/packages/opgg-riotquest)

PHPackages © 2026

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