# API Docs

### Authorization

When interacting with the API, for most requests, you'll need to provde an authorization header. It should look like this:

```
Authorization: Basic {base64 encoding of: "username:password"}
```

For example, it may look something like:

```
Authorization: Basic bmV2ZXJnb25uYTpnaXZleW91dXA=
```

### License Management

## License Check

<mark style="color:green;">`POST`</mark> `/check`

Checks the validity of any given license.

#### Request Body

| Name                                      | Type   | Description                                     |
| ----------------------------------------- | ------ | ----------------------------------------------- |
| license<mark style="color:red;">\*</mark> | String | The license ID.                                 |
| product<mark style="color:red;">\*</mark> | String | The ID of the product that this license is for. |

{% tabs %}
{% tab title="404: Not Found If the license isn't found, or the license isn't for the product id that you provided, you'll recieve an error." %}
Code: 10
{% endtab %}

{% tab title="400: Bad Request If you provided any invalid fields. " %}
Code: 30
{% endtab %}

{% tab title="403: Forbidden If the license has had too many unique IPs connect to it." %}
Code: 20
{% endtab %}

{% tab title="200: OK If the license was valid." %}

{% endtab %}

{% tab title="500: Internal Server Error If there was an internal server error." %}

{% endtab %}
{% endtabs %}

## Create License

<mark style="color:green;">`POST`</mark> `/license`

#### Headers

| Name                                            | Type   | Description                                            |
| ----------------------------------------------- | ------ | ------------------------------------------------------ |
| Authorization<mark style="color:red;">\*</mark> | String | You'll need an [authorization header](#authorization). |

#### Request Body

| Name                                        | Type   | Description                                                                                    |
| ------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------- |
| product<mark style="color:red;">\*</mark>   | String | The ID of the product that this license is for.                                                |
| max\_ips                                    | int    | Maximum amount of unique IPs that can use this license.                                        |
| expires                                     | String | <p>How long until this license should expire. In this format:<br><br><code>1d2h3m4s</code></p> |
| note                                        | String | You can add an optional note for the license.                                                  |
| owner\_id<mark style="color:red;">\*</mark> | String | The ID of the user that owns this license.                                                     |

{% tabs %}
{% tab title="404: Not Found If the provided product ID could not be found." %}

{% endtab %}

{% tab title="400: Bad Request If you proivded an invalid payload." %}

{% endtab %}

{% tab title="200: OK If the license was created successfully." %}

{% endtab %}

{% tab title="401: Unauthorized If you provided an invalid username or password." %}

{% endtab %}
{% endtabs %}

### Product Management

## Get Products

<mark style="color:blue;">`GET`</mark> `/products`

Retrieves all products.

#### Headers

| Name                                            | Type   | Description                                            |
| ----------------------------------------------- | ------ | ------------------------------------------------------ |
| Authorization<mark style="color:red;">\*</mark> | String | You'll need an [authorization header](#authorization). |

{% tabs %}
{% tab title="401: Unauthorized If you provided an invalid username or password." %}

{% endtab %}

{% tab title="200: OK Returns a JSON array of all products" %}

{% endtab %}
{% endtabs %}

## Get Product

<mark style="color:blue;">`GET`</mark> `/product/{id}`

Retrieves a product by its ID.

#### Path Parameters

| Name                                 | Type   | Description    |
| ------------------------------------ | ------ | -------------- |
| id<mark style="color:red;">\*</mark> | String | The product ID |

#### Headers

| Name                                            | Type   | Description                                            |
| ----------------------------------------------- | ------ | ------------------------------------------------------ |
| Authorization<mark style="color:red;">\*</mark> | String | You'll need an [authorization header](#authorization). |

{% tabs %}
{% tab title="400: Bad Request If the product can't be found." %}

{% endtab %}

{% tab title="200: OK Returns the product as JSON." %}

{% endtab %}

{% tab title="401: Unauthorized If you provided an invalid username or password." %}

{% endtab %}
{% endtabs %}

## Create Product

<mark style="color:green;">`POST`</mark> `/products`

Creates a product

#### Headers

| Name          | Type   | Description                                            |
| ------------- | ------ | ------------------------------------------------------ |
| Authorization | String | You'll need an [authorization header](#authorization). |

#### Request Body

| Name                                          | Type   | Description                |
| --------------------------------------------- | ------ | -------------------------- |
| name<mark style="color:red;">\*</mark>        | String | Name of the product.       |
| description<mark style="color:red;">\*</mark> | String | Description of the product |

{% tabs %}
{% tab title="200: OK Created product sucessfully." %}

{% endtab %}

{% tab title="400: Bad Request Invalid JSON or invalid or missing values provided." %}

{% endtab %}

{% tab title="401: Unauthorized Invalid auth header." %}

{% endtab %}
{% endtabs %}

## Modify Product

<mark style="color:orange;">`PUT`</mark> `product/{id}`

Modifes a product. You must have at least one of the body parameteres, or you'll be given a 400 error. If any of the values are provided as null, they will not be changed.

#### Path Parameters

| Name                                 | Type   | Description                                |
| ------------------------------------ | ------ | ------------------------------------------ |
| id<mark style="color:red;">\*</mark> | String | ID of the product that you want to modify. |

#### Headers

| Name                                            | Type   | Description                                            |
| ----------------------------------------------- | ------ | ------------------------------------------------------ |
| Authorization<mark style="color:red;">\*</mark> | String | You'll need an [authorization header](#authorization). |

#### Request Body

| Name        | Type   | Description                     |
| ----------- | ------ | ------------------------------- |
| name        | String | New name of the product         |
| description | String | New description of the product. |

{% tabs %}
{% tab title="400: Bad Request Either you provided invalid JSON or you didn't provide a valid value to change." %}

{% endtab %}

{% tab title="404: Not Found If the product can't be found." %}

{% endtab %}

{% tab title="401: Unauthorized If you provided an invalid authorization header or invalid credentials." %}

{% endtab %}

{% tab title="200: OK Successfully modified the product." %}

{% endtab %}
{% endtabs %}

## Delete Product

<mark style="color:red;">`DELETE`</mark> `/product/{id}`

Deletes a product by ID.

#### Path Parameters

| Name                                 | Type   | Description                                    |
| ------------------------------------ | ------ | ---------------------------------------------- |
| id<mark style="color:red;">\*</mark> | String | The ID of the product that you want to delete. |

#### Headers

| Name                                            | Type   | Description                                            |
| ----------------------------------------------- | ------ | ------------------------------------------------------ |
| Authorization<mark style="color:red;">\*</mark> | String | You'll need an [authorization header](#authorization). |

{% tabs %}
{% tab title="401: Unauthorized If you provided an invalid username or password." %}

{% endtab %}

{% tab title="200: OK If the product was deleted successfully." %}

{% endtab %}

{% tab title="404: Not Found If the product can not be found." %}

{% endtab %}
{% endtabs %}
