# Order and Product Filtering

The Skyhub API has a feature to filter orders and products accordingly to the status that they are in.

### Filter Orders by Status

For example, when you perform the `GET` through the endpoint `https://api.skyhub.com.br/orders/`, the result bring all the orders, regardless of whether they are approved, sent, canceled, delivered, and so on ...

By using the filter, we can search for an specific status. In order to do that you need to know what status your store has on Skyhub by cheking the order statuses through the following path within Skyhub plataform portal following the path: **"Skyhub" > "status de pedidos"**

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpDngA7eMdO8AuxmkY%2Fimage.png?alt=media\&token=a18e3b7b-cf11-4532-86cd-d3fd5884371b)

{% hint style="info" %}
The status used to make the filter are avaiable at the field # (code)
{% endhint %}

You can also check the different types of statuses through the endpoint: `api.skyhub.com.br/statuses`

![response sample](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpEqPw3Ir3g4bC4JAY%2Fimage.png?alt=media\&token=385e313b-71ac-490a-8cb4-98ac3d7e219e)

### How to Filter Requests by Status?

To filter, we must use the `GET` method at the `https://api.skyhub.com.br/orders?filters[statuses][]={code}` endpoint with the following Headers:

```
X-User-Email: YOUR_EMAIL
X-Api-Key: YOUR_API_KEY
X-Accountmanger: YOUR_X_ACCOUNTMANAGER-KEY
Accept: application/json
Content-Type: application/json
```

Using Skyhub's standard statuses, the endpoints would be:

| Action                      | Request                                                                        |
| --------------------------- | ------------------------------------------------------------------------------ |
| **Approved Orders**         | https://api.skyhub.com.br/orders?filters\[statuses]\[]=payment\_received       |
| **Invoice Issued**          | <p>https://api.skyhub.com.br/orders?filters[statuses][]=order_invoiced<br></p> |
| **Pending payment**         | https://api.skyhub.com.br/orders?filters\[statuses]\[]=book\_product           |
| **Canceled**                | https://api.skyhub.com.br/orders?filters\[statuses]\[]=order\_canceled         |
| **Delivered to Customer**   | <p>https://api.skyhub.com.br/orders?filters[statuses][]=complete<br></p>       |
| **order posted do carrier** | https://api.skyhub.com.br/orders?filters\[statuses]\[]=order\_shipped          |

See the example below:

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpHHXm3-U_s1U7hsHl%2Fimage.png?alt=media\&token=3d449077-6047-4012-bec3-5f74d257f32f)

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpHJfxoLsRvqL8rpQN%2Fimage.png?alt=media\&token=100a7188-1e7b-4080-bf08-ff8c55f6624f)

In case your store has many orders by status, you can also filter by page using the "page" and "per\_page".

* Page: indicates the page number of the records that will be returned. If not specified, the first page is returned (default value 1).
* Per\_page: Indicates the number of records to be returned. In both endpoints (products and orders), per\_page has 100 as default and maximum value.

{% code title="Example:" %}
```
https://api.skyhub.com.br/orders?filters[statuses][]=payment_received&page=1&per_page=1
```
{% endcode %}

In the example above, we are looking for approved status orders that appear on the first page.

{% hint style="danger" %}
Caution: Status filtering feature should **NOT** be used under any circumstances for order consumption/download always use the order queue endpoint.
{% endhint %}

### How to filter requests by date:

To filter requests by date, you'll need to use `filters [start_date] = DD / MM / YYYY`

{% code title="Example:" %}
```
https://api.skyhub.com.br/orders?filters[start_date]=15/08/2018
```
{% endcode %}

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpJ7UpN14NethhEWjY%2Fimage.png?alt=media\&token=3c7250a7-ec24-4d79-ac3a-ce1317e44c22)

In the example above we can see that the filter used is `[start_date] = 15/08/2018`, in this case the request response is those orders created from 08/15/2018 onwards.

To filter just the orders at 08/15/2018, you will also need to use `[end_date] = DD / MM / YYYY`.

{% code title="Example:" %}
```
https://api.skyhub.com.br/orders?filters[start_date]=15/08/2018&filters[end_date]=15/08/2018
```
{% endcode %}

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpN0Ccmhnb1qeKS6Et%2Fimage.png?alt=media\&token=8d212814-9ecc-4dd4-a9bc-4a7f96d0676c)

If we look at the responses from the last two images above, we see that the number of requests returned are divergent, because the 1° example returns orders to day 15 onwards and 2° one only the requests from day 15.

{% hint style="info" %}
To check the date, you must verify the information presented in the "placed\_at" field.
{% endhint %}

The filter by date will always be performed by **the order creation date**, never by its update date.

### Filter products by status

In Skyhub's Api, in addition to filtering orders by status, we also have the possibility to filter products by status.

What are the product statuses?

* Enabled
* Disabled

#### How do I filter products by status?

To filter a product by status, you must use the headers bellow at `https://api.skyhub.com.br/products?filters[status]={enabled ou disabled}` endpoint.

```
X-User-Email: YOU_EMAIL
X-Api-Key: YOUR_API_KEY
X-Accountmanger: YOUR_X_ACCOUNTMANAGER-KEY
Accept: application/json
Content-Type: application/json
```

Here is an example of a request:

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpRA1IMbt3hUAnUNf7%2Fimage.png?alt=media\&token=33bb0a9b-f0db-454a-bd33-39303fd06fef)

Result

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpRCK80q8-wEBjgmkP%2Fimage.png?alt=media\&token=b5f2c6a3-ea6b-42a6-8541-238d817cafc7)

As in orders, you can filter by status, page, and quantity:

```
https://api.skyhub.com.br/products?page=1&per_page=1&filters[status]=enabled
```

![](https://2606423342-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWLii0XmQdjJQQG6m8e%2F-LWpCSn_TX4TENIRBiUF%2F-LWpROZEKolbn5BJdcdI%2Fimage.png?alt=media\&token=9ba98ad7-d04e-4bc3-a215-d2a028eafbf4)

As we can see in the example above, the product was filtered with the status "enabled", bringing page 1 and only 1 product.

#### Other filters

In addition to the filters already mentioned, Skyhub has other types of filters.

* filters\[sku]
* filters\[name]
* filters\[status]
* filters\[qty\_from]
* filters\[qty\_to]
