> For the complete documentation index, see [llms.txt](https://aerogcs-api-docs.aeromegh.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aerogcs-api-docs.aeromegh.com/aerogcs-enterprise-apis/get-all-crops.md).

# Get All Crops

"Dive into the world of crops effortlessly with Aeromegh's crop data API."

This API provides programmatic access to crop data, including types and quantities, with secure API key authentication. Explore the endpoints below for details on parameters and responses.

### Authentication&#x20;

To use the API, insert your API key in the Authorization header like this:

```javascript
Authorization: Bearer <YOUR_API_KEY>
```

Replace `<YOUR_API_KEY>` with your AeroGCS API key. Without it, you'll get a 401 Unauthorized error.

### Method

**GET : Retrieves a list of all crops.**

### HTTP Request <a href="#http-request-33" id="http-request-33"></a>

{% code overflow="wrap" %}

```url
https://ags.aeromegh.com/Aeromegh/getAllCrops?searchString={searchString}&fromDateTime={fromDateTime}&toDateTime={toDateTime}&orderBy={orderBy}&orderType={orderType}&pageSize={pageSize}&pageNumber={pageNumber}

```

{% endcode %}

### URL Parameters <a href="#http-response-32" id="http-response-32"></a>

URL parameters are:

| Parameter        | Description                                          | Optional | Example                  |
| ---------------- | ---------------------------------------------------- | -------- | ------------------------ |
| **searchString** | Users can search by crop type.                       | Yes      |                          |
| **fromDateTime** | Start date and time in UTC.                          | Yes      | 2023-08-19T00:00:20.335Z |
| **toDateTime**   | End date and time in UTC.                            | Yes      | 2024-05-07T23:59:20.335Z |
| **orderBy**      | Field name to order by; default field is crop\_type. | Yes      | crop\_type               |
| **orderType**    | Sorting order, either ASC or DESC; default is DESC.  | Yes      | DESC                     |
| **pageSize**     | Number of records shown on each page.                | Yes      | 15                       |
| **pageNumber**   | Page number; must be greater than zero.              | Yes      | 1                        |

### HTTP Response <a href="#http-response-32" id="http-response-32"></a>

Response Codes Explanation:

| Code | Details                     | Message                      |
| ---- | --------------------------- | ---------------------------- |
| 200  | The request was successful. | "OK"                         |
| 400  | Request parameters missing. | "Request parameters missing" |
| 500  | Internal server error.      | "Internal server error"      |

### Code Snippet

Examples of how you can call this API using curl, Node.js, and Python:

{% tabs %}
{% tab title="curl" %}

```url
curl --location 'https://ags.aeromegh.com/Aeromegh/getAllCrops?searchString=&fromDateTime=2023-08-19T00%3A00%3A20.335Z&toDateTime=2024-05-07T23%3A59%3A20.335Z&orderBy=crop_type&orderType=DESC&pageSize=15&pageNumber=1' \
--header 'Authorization: Bearer <API_KEY>'
```

{% endtab %}

{% tab title="Node" %}

```javascript
//Please install 'axios' module first
//Set your API key before making the request

const axios = require('axios');

let config = {
  method: 'get',
  maxBodyLength: Infinity,
  url: 'https://ags.aeromegh.com/Aeromegh/getAllCrops?searchString=&fromDateTime=2023-08-19T00:00:20.335Z&toDateTime=2024-05-07T23:59:20.335Z&orderBy=crop_type&orderType=DESC&pageSize=15&pageNumber=1',
  headers: { 
    'Authorization': 'Bearer <API_KEY>'
  }
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

```

{% endtab %}

{% tab title="Python" %}

```python
//Please install 'requests' package first
//Set your API key before making the request
import requests

url = "https://ags.aeromegh.com/Aeromegh/getAllCrops?searchString=&fromDateTime=2023-08-19T00:00:20.335Z&toDateTime=2024-05-07T23:59:20.335Z&orderBy=crop_type&orderType=DESC&pageSize=15&pageNumber=1"

payload = {}
headers = {
  'Authorization': 'Bearer <API_KEY>'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Note:** Replace **`<API_KEY>`** with the actual API\_KEY provided by Aeromegh.
{% endhint %}

### &#x20;API Response

Example of API response in JSON format:

```json
{
    "allCrops": [
        {
            "crop_type": "rice"
        },
        {
            "crop_type": "jawar"
        }
    ]
}
```

### API Response Parameter&#x20;

The following parameter is included in API response

| Parameter      | Description                               | Example |
| -------------- | ----------------------------------------- | ------- |
| **crop\_type** | The type of crop returned in the response | rice    |
