# Managing Orders through API

Welcome to the Fungies API documentation! This guide will walk you through managing orders using the Fungies API. You'll learn how to list orders, retrieve specific order details, update an order, and cancel an order.

After generating the `API key` and `write-API key` you can immediately start making requests to the Fungies Orders API endpoints

## Getting Started with APIs

A collection of endpoints that allow you to manage and interact with orders, including retrieving details, updating, and cancelling orders, to ensure seamless order management and processing.

### /orders/list (List All Orders)

The `/orders/list` endpoint is used to retrieve a list of all orders from the Fungies.io platform. It allows developers to access details of every order placed within the system, providing an overview of order activities.

> **Note**: This endpoint requires `API key` for authentication.

This is a `GET` API endpoint that accepts several parameters to filter the results:

* **status**: Specifies the current status of the orders. Possible values include `PENDING`, `PAID`, `FAILED`, `UNPAID`, `CANCELLED`, `REFUNDED`, `PARTIALLY_REFUNDED`, and `EXPIRED`.
* **userId**: Filters orders by the user ID of the customer.
* **createdAfter**: Returns orders created after a specified date.
* **createdBefore**: Returns orders created before a specified date.
* **page**: Specifies which page of the order list you want to retrieve.
* **limit**: Defines the maximum number of orders to return per page.

**Successful Response:**

When the request is successful, you will receive a response like this:

```
{
  "status": "success",
  "data": {
    "orders": [
      {
        "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "status": "PENDING",
        "orderNumber": "string",
        "value": -1.7976931348623157e+308,
        "fee": -1.7976931348623157e+308,
        "tax": -1.7976931348623157e+308,
        "currency": "AFN",
        "createdAt": "string",
        "formatted": {
          "orderNumber": "string",
          "subtotal": "string",
          "totalValue": "string",
          "totalDiscount": "string",
          "tax": "string"
        }
      }
    ],
    "count": -1.7976931348623157e+308
  }
}
```

**Error Response:**

If the request fails, you will receive an error response like this:

```
{
  "status": "error",
  "error": {
    "message": "Sample error message"
  }
}
```

### /orders/orderId (Retrieve Order Details)

The GET `/orders/{orderId}` endpoint retrieves detailed information about a specific order based on the unique orderId. This endpoint is essential for accessing comprehensive details about an individual order, including its status, items, payment information, and customer details.

> **Note**: This endpoint requires `API key` for authentication.

This is a `GET` API endpoint that accepts a single parameter to filter the results:

* **orderId:** The orderId parameter is a unique identifier for a specific order in the Fungies.io platform.

**Successful Response:**

When the request is successful, you will receive a response like this:

```
{
  "status": "success",
  "data": {
    "order": {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "status": "PENDING",
      "orderNumber": "string",
      "value": -1.7976931348623157e+308,
      "fee": -1.7976931348623157e+308,
      "tax": -1.7976931348623157e+308,
      "currency": "AFN",
      "createdAt": "string",
      "formatted": {
        "orderNumber": "string",
        "subtotal": "string",
        "totalValue": "string",
        "totalDiscount": "string",
        "tax": "string"
      }
    }
  }
}
```

**Error Response:**

If the request fails, you will receive an error response like this:

```
{
  "status": "error",
  "error": {
    "message": "Sample error message"
  }
}
```

### /orders/{orderId}/update (Update an Order)

The PATCH `/orders/{orderId}/update` endpoint allows you to update the details of a specific order identified by the orderId. This endpoint is useful for modifying order attributes such as status, shipping information, or any other modifiable fields after creating the order.

> **Note**: This endpoint requires `API key` and `write-API key` (both) for authentication at the same time.

The `/orders/{orderId}/update` endpoint allows users to update an order by sending a request with the following values in the request body:

* **status**: The current status of the order.
* **value**: The total value of the order.
* **fee**: Any fees associated with the order.
* **tax**: The amount of tax applied to the order.
* **currency**: The currency used for the order.

**Request Body:**

```
{
  "status": "PENDING",
  "value": -1.7976931348623157e+308,
  "fee": -1.7976931348623157e+308,
  "tax": -1.7976931348623157e+308,
  "currency": "AFN"
}
```

**Successful Response:**

When the request is successful, you will receive a response like this:

```
{
  "status": "success",
  "data": {
    "order": {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "status": "PENDING",
      "orderNumber": "string",
      "value": -1.7976931348623157e+308,
      "fee": -1.7976931348623157e+308,
      "tax": -1.7976931348623157e+308,
      "currency": "AFN",
      "createdAt": "string",
      "formatted": {
        "orderNumber": "string",
        "subtotal": "string",
        "totalValue": "string",
        "totalDiscount": "string",
        "tax": "string"
      }
    }
  }
}
```

**Error Response:**

If the request fails, you will receive an error response like this:

```
{
  "status": "error",
  "error": {
    "message": "Sample error message"
  }
}
```

### /orders/{orderId}/cancel (Cancel an Order)

The PATCH `/orders/{orderId}/cancel` endpoint is used to cancel a specific order identified by the orderId. This endpoint is typically used when an order needs to be stopped before it is fulfilled or processed. Cancelling an order will update its status to indicate that it has been cancelled.

> **Note**: This endpoint requires `API key` and `write-API key` (both) for authentication at the same time.

This is a PATCH API endpoint that accepts a single parameter to cancel/delete the results:

**orderId:** The orderId parameter is a unique identifier for a specific order in the Fungies.io platform.

The `/orders/{orderId}/cancel` endpoint does not require a request body; it uses an empty request body.

**Successful Response:**

When the request is successful, you will receive a response like this:

```
{
  "status": "success",
  "data": {
    "order": {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "status": "PENDING",
      "orderNumber": "string",
      "value": -1.7976931348623157e+308,
      "fee": -1.7976931348623157e+308,
      "tax": -1.7976931348623157e+308,
      "currency": "AFN",
      "createdAt": "string",
      "formatted": {
        "orderNumber": "string",
        "subtotal": "string",
        "totalValue": "string",
        "totalDiscount": "string",
        "tax": "string"
      }
    }
  }
}
```

**Error Response:**

If the request fails, you will receive an error response like this:

```
{
  "status": "error",
  "error": {
    "message": "Sample error message"
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.fungies.io/for-saas-developers/orders-apis/managing-orders-through-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
