> For the complete documentation index, see [llms.txt](https://itwithlyam.gitbook.io/orders-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://itwithlyam.gitbook.io/orders-api/master.md).

# Specification

**The Orders API is a RESTful API for users to track and check the status of IT with Lyam orders. This API can also add and resolve orders.**<br>

## **Title**

**Orders API**<br>

## **Problem**

**We are currently manually tracking orders, and clients should be able to submit orders 24/7.**<br>

## **Solution**

**Build a RESTful API that a client (e.g. via Discord) can connect to.**<br>

## **Implementation**

**We have decided to use the REpresentational State Transfer (REST) Protocol for the following reasons:**

* **The REST resource paradigm matches how we treat files in our Database**
* **We don’t need more than CRUD operations for now**
* **Event monitoring will come in the future**

## **Authentication**

**To check that API users have access to the chosen resource, we will create a page for the Orders API on IWL-L. This will create asecurely hashed Authorization token, which is then added to our Database. The API will check for the “Authorization” header during the request, and will send Error 401 Not Authorized if it does not exist and Error 403 Forbidden if the token does not have access to the selected resource.**<br>

![](https://lh6.googleusercontent.com/qvQxoBCoY4XIGf1alfS3GCkGxskzolJ2va0wy-N4VKAtSwOd7Zj7SRMI1rZrDMxQtI3u9NhDbrl88o8lifKSYVl7roBv8f_AEKEQQ3n7kbhf3uaEMlXtVsvd3j4od44PxazexnXL=s0)

**Above: The Authorization flow**<br>

## **Considerations**

**The currently planned V2 of IWL-L will include a “WebSocket Gateway”, where there will be events interacting with the Orders API. These may include “ORDER\_CREATE”, “ORDER\_RESOLVE” and “ORDER\_DELETE”. However, this is long in the future. We might also switch to OAuth 2.0 Authentication, but IWL-L is an easy in-house solution. Using GraphQL for some operations also seems logical, but it would be optional.**

## **REST Endpoints**

| **URI**                                                           | **Inputs**                                                                                                                                                                                                                                             | **Outputs**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Scope**     | **Added yet**      |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- | ------------------ |
| <p><strong>GET</strong></p><p><strong>/orders</strong></p>        | <p><strong>Required: N/A</strong></p><p><strong>Optional:</strong></p><p><strong>Limit (int)</strong></p><p><strong>default 100, max 1000</strong><br></p><p><strong>last\_updated\_after (timestamp)</strong></p><p><strong>default null</strong></p> | <p><strong>200 OK</strong></p><p><strong>Array of Orders</strong></p><p><strong>\[</strong></p><p> <strong>{</strong></p><p>  <strong>“id”: orderId,</strong></p><p>  <strong>“name”: string,</strong></p><p>  <strong>“timestamp”: timestamp,</strong></p><p>  <strong>“last\_updated”: timestamp,</strong></p><p>  <strong>“payment”: int,</strong></p><p>  <strong>“is\_deleted”: boolean,</strong></p><p>  <strong>“notes”: array of Notes,</strong> </p><p>  <strong>“resolved”: string</strong></p><p> <strong>}</strong></p><p><strong>]</strong></p> | **moderator** | **Yes**            |
| <p><strong>GET</strong></p><p><strong>/orders/:id</strong></p>    | **N/A**                                                                                                                                                                                                                                                | <p><strong>200 OK</strong></p><p><strong>Order Object</strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | **read+**     | **Yes**            |
| <p><strong>PATCH</strong></p><p><strong>/orders/:id</strong></p>  | <p><strong>Updatable fields:</strong></p><p><strong>name (string)</strong></p><p><strong>payment (int)</strong></p><p><strong>name (string)</strong></p><p><strong>resolved (string)</strong> </p>                                                     | <p><strong>202 Accepted</strong></p><p><strong>Order Object</strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | **write+**    | **In Development** |
| <p><strong>POST</strong></p><p><strong>/orders</strong></p>       | <p><strong>Required:</strong></p><p><strong>name (string)</strong></p><p><strong>payment (int)</strong></p>                                                                                                                                            | <p><strong>200 Created</strong></p><p><strong>Order Object</strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | **write**     | **No**             |
| **DELETE /orders/:id**                                            | <p><strong>Required:</strong></p><p><strong>resolved (string)</strong></p>                                                                                                                                                                             | **204 No Response**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | **moderator** | **No**             |
| <p><strong>POST</strong></p><p><strong>/orders/notes</strong></p> | <p><strong>Required:</strong></p><p><strong>notes (array of Notes)</strong></p>                                                                                                                                                                        | **200 Created**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | **developer** | **No**             |

\
**Errors**&#x20;
----------------

| **HTTP Code** | **Verbose error**       | **Description**                                           |
| ------------- | ----------------------- | --------------------------------------------------------- |
| **200-299**   | **SUCCESS**             | **Success**                                               |
| **304**       | **NO\_CONTENT**         | **No content was returned**                               |
| **400**       | **BAD\_REQUEST**        | **We received an improper request**                       |
| **401**       | **NOT\_AUTHORIZED**     | **The Authorization header was missing**                  |
| **403**       | **FORBIDDEN**           | **You do not have access to the resource**                |
| **404**       | **NOT\_FOUND**          | **The resource was not found**                            |
| **429**       | **TOO\_MANY\_REQUESTS** | **Rate limited**                                          |
| **500+**      | **INTERNAL\_ERROR**     | **There was an error in our system! Please report this.** |

## **Rate limiting**

**Our API allows up to 25 requests in 3 minutes. Any violations will result in 429 Too Many Requests. All violations are logged, and repeated violations can escalate to a token or IP ban. This should be more than enough time, since each request takes a couple of seconds to resolve.**

| **Name**                  | **Description**                  | **Example** |
| ------------------------- | -------------------------------- | ----------- |
| **X-RateLimit-Limit**     | **Request limit**                | **25**      |
| **X-RateLimit-Remaining** | **Remaining available requests** | **24**      |
| **X-RateLimit-Reset**     | **Seconds to rate limit reset**  | **60**      |

## **Feedback plan**

**The Orders API will be released to Beta Testers along with IWL-L, as they are built together. Beta Testers will be asked via a Google Form for feedback.**<br>

{% hint style="info" %}
**See this (and more) at** [**https://spec.itwithlyam.co.uk**](https://spec.itwithlyam.co.uk)
{% endhint %}
