# Rest API

The Player Economy REST API extends the capabilities of the Player Economy plugin, allowing interaction with plugin objects and events from outside the Minecraft server environment. This documentation provides a comprehensive guide to using the API, including its endpoints, WebSocket functionality, and authentication mechanisms.

The base URL for the Player Economy REST API is determined by the server administrator. Please remember to include the base URL of the server where the Player Economy API is hosted, which can probably be found on the servers documentation.

## Authentication

To interact with the **Player Economy REST API** or **WebSocket**, authentication is required to ensure secure access. We use **Basic Authentication**, where:

* **Username**: Your **Minecraft UUID** (You can find your **FULL UUID** [here](https://mcuuid.net/?q=ForgotUrPassword)).
* **Password**: Your **API Key** (a unique token generated for your account to interact with the API).

#### Generating an API Key

To generate an API token, use the command:

```bash
/peconomy apitokens generate
```

This will create a new API token for your account, which can then be used for authentication in your API requests. **Do not share your API token with anyone else, as it provides access to your account and data.**

#### API Key Limitations

* You can only have **one active API token** at a time.
* If you generate a new API token using `/peconomy apitokens generate`, it will **replace** your existing API token. The previous token will no longer be valid.
* If you wish to delete your API token without generating a new one, use the following command:

  ```arduino
  /peconomy apitokens delete
  ```

  This will delete your existing API token, but **will not generate a new one**. You will need to generate a new token manually if required.

#### Example API Request

Here’s how to authenticate API requests using your Minecraft UUID and API token:

**Request Header**:

```http
Authorization: Basic {Base64 encoded string of 'UUID:API_KEY'}
```

In this case, the base64 encoded string would be a combination of your Minecraft UUID and API Key (separated by a colon). You can use your program to easily generate the base64 encoding.

## Endpoints

You will find a comprehensive list of all the available API endpoints for interacting with the Player Economy plugin. Each endpoint includes detailed descriptions, request methods, parameters, and responses.

To view the available endpoints, go to the [Endpoints](https://docs.olziedev.com/projects/playereconomy/restapi/endpoints) page.

## Events

The Player Economy API also supports real-time event handling through WebSockets. This section covers connecting, subscribing, and receiving events like depositing or withdrawing money.

Go to the [Events](https://docs.olziedev.com/projects/playereconomy/restapi/events) page for details on subscribing to and receiving WebSocket events.

## Errors

The Player Economy API can throw errors, and you will need to catch them! You can view them [here](https://docs.olziedev.com/projects/playereconomy/restapi/errors).
