# UserApiClientEvent events

> 4 FeatherPanel plugin events on UserApiClientEvent (3 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/user-api-client/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 1 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `UserApiClientEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\UserApiClientEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(UserApiClientEvent::onUserApiClientDeleted(), function ($userUuid, $apiClient): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:deleted ' . json_encode(['user_uuid' => $userUuid, 'api_client' => $apiClient]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `UserApiClientEvent::onUserApiClientCreated()`

- Name: `featherpanel:user:api_client:created`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserApiClientEvent.php#L28)

Docblock: array api\_client data. (the emitter passes 2 values, see the table)

Same event name as `UserEvent::onUserApiKeyCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `api_client` | `$apiClient` | not declared |

When it fires (1 site)

-   [`ApiClientController::createApiClient`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L407)[`POST /api/user/api-clients`](https://featherpanel.com/docs/api/reference/user/api-clients/#post-user-api-clients)

```php
$event->on(UserApiClientEvent::onUserApiClientCreated(), function ($userUuid, $apiClient): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:created');
});
```

## `UserApiClientEvent::onUserApiClientDeleted()`

- Name: `featherpanel:user:api_client:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserApiClientEvent.php#L44)

Docblock: int api\_client id, array api\_client data.

Same event name as `UserEvent::onUserApiKeyDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `int`from docblock |
| 2 | `api_client` | `$apiClient` | `array`from docblock |

When it fires (1 site)

-   [`ApiClientController::deleteApiClient`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L799)[`DELETE /api/user/api-clients/{id}`](https://featherpanel.com/docs/api/reference/user/api-clients/#delete-user-api-clients-id)

```php
$event->on(UserApiClientEvent::onUserApiClientDeleted(), function ($userUuid, $apiClient): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:deleted ' . json_encode(['user_uuid' => $userUuid, 'api_client' => $apiClient]));
});
```

## `UserApiClientEvent::onUserApiClientError()`

- Name: `featherpanel:user:api_client:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserApiClientEvent.php#L53)

Docblock: string error message, array context.

```php
$event->on(UserApiClientEvent::onUserApiClientError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `UserApiClientEvent::onUserApiClientUpdated()`

- Name: `featherpanel:user:api_client:updated`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserApiClientEvent.php#L36)

Docblock: int api\_client id, array updated data. (the emitter passes 3 values, see the table)

Same event name as `UserEvent::onUserApiKeyUpdated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `api_client` | `$apiClient` | not declared |
| 3 | `updated_data` | `$updatedData`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `api_client`, `updated_data` | 
`ApiClientController::updateApiClient`

 |
| `user_uuid`, `api_client`, `action` | 

`ApiClientController::regenerateApiKeys`

 |

When it fires (2 sites)

-   [`ApiClientController::updateApiClient`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L717)[`PUT /api/user/api-clients/{id}`](https://featherpanel.com/docs/api/reference/user/api-clients/#put-user-api-clients-id)
-   [`ApiClientController::regenerateApiKeys`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L890)[`POST /api/user/api-clients/{id}/regenerate`](https://featherpanel.com/docs/api/reference/user/api-clients/#post-user-api-clients-id-regenerate)

```php
$event->on(UserApiClientEvent::onUserApiClientUpdated(), function ($userUuid, $apiClient, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:updated');
});
```
