# Harvest Scheduler

Harvest Scheduler data can be accessed via the following API calls

## Harvest Scheduler Raw Data (API Authentication)

<mark style="color:blue;">`GET`</mark> `https://<domain>.vinoez.com/api/harvest-scheduler-raw-data-v2`

Pulls all Harvest Scheduler loads as raw data using JWT (JSON Web Token) Authentication. (Please see the "Authentication" section of the APIs documentation for instructions on how to receive a JWT)\
At this endpoint, the user will be required to provide their credentials in the Header as `Authorization Bearer <JWT_Token_Retrieved_From_API_Login_Endpoint_Here>`

NOTE: If `asJson` is passed through with a value of `1`, the `load_status` will also be included in the payload.

#### Query Parameters

| Name                     | Type    | Description                                                                                                                                                                                                             |
| ------------------------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| onlyAllocationsWithPicks | string  | Pass a "false" value (`onlyAllocationsWithPicks=false`) if you want to receive **all** Allocations, even those without picks/loads, for the harvest period.                                                             |
| startDate                | string  | The date that the data should start from, formatted as `YYYY-MM-DD` (i.e., "2021-07-17") **NOTE:** If you plan to use the `dateRange` query, you must include the `startDate`.                                          |
| dateRange                | integer | <p>The number of days from the start date (i.e., 14). <br><strong>NOTE:</strong> if the <code>startDate</code> query is included, but the <code>dateRange</code> is not passed through, we will default to 21 days.</p> |
| location                 | string  | The location code (i.e., "BER")                                                                                                                                                                                         |
| year                     | string  | The year of harvest, formatted as `YYYY` (i.e., "2021") **NOTE** that if this is not included, we will use the current year.                                                                                            |
| asJson                   | int     | By default, this endpoint will return a csv. Include this query parameter, and pass through `1` if results should be returned in JSON format, `0` if they should not.                                                   |

#### Headers

| Name          | Type   | Description        |
| ------------- | ------ | ------------------ |
| vino\_app     | string | mobile             |
| Authorization | string | `Bearer {{token}}` |

{% tabs %}
{% tab title="200 All raw data returned as csv" %}

```
load_id,load_quantity,start_time,receive_time,harvest_method,bins,receive_area,hauler,load_comments,block_id,block_code,block_name,field_grade,appellation,planning_region,region,grower_name,rep_name,varietal,farm_type,district,allocation_id,crush_site,eur,current_estimate,pick_id,pick_date,pick_quantity,pick_type,pick_manager 1,2,02:00,02:00:00,"Hand Picked",0,CP3,,,2,FV-001A,1A,B1,STHU,"Napa County","Central Coast","Freitas Vineyards","Enzo Deia",CAS,External,01,1,ZAM,ZAMNVCAS18,44,2,2021-08-22,26,"Pick Called",Jane
```

{% endtab %}

{% tab title="400 No token provided with JWT auth" %}

```
"error":"token_absent"
```

{% endtab %}
{% endtabs %}

## Harvest Scheduler Raw Data (Basic Authentication)

<mark style="color:blue;">`GET`</mark> `https://<domain>.vinoez.com/api/v1/harvest-scheduler-raw-data`

Pulls all Harvest Scheduler loads as raw data, using a basic authentication login form. At this endpoint, the user will be asked to provide their credentials in the UI.

#### Query Parameters

| Name                     | Type    | Description                                                                                                                                                        |
| ------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| onlyAllocationsWithPicks | string  | Pass a "false" value (`onlyAllocationsWithPicks=false`) if you want to receive **all** Allocations, even those without picks/loads, for the harvest period.        |
| startDate                | string  | The date that the data should start from, formatted as `YYYY-MM-DD` (i.e., "2021-07-17")                                                                           |
| dateRange                | integer | Number of days from the start date (i.e., 14) **NOTE** that if the `startDate` is included, but the `dateRange` is not passed through, we will default to 21 days. |
| year                     | string  | The year of harvest, formatted as `YYYY` (i.e., "2021") **NOTE** that if this is not included, we will use the current year.                                       |
| location                 | string  | The location code (i.e., "BER")                                                                                                                                    |

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

```
```

{% endtab %}
{% endtabs %}

## Latest Harvest Scheduler Load Data (API Authentication)

<mark style="color:blue;">`GET`</mark> `https://<domain>.vinoez.com/api/get-latest-load-data`

Pulls latest data for picks with loads using the "lastUpdated" timestamp provided and returns JSON payload containing Harvest Scheduler data, along with an array of IDs representing **all** Loads (*regardless of year or location value*) that have been deleted since the `lastUpdated` timestamp.

NOTE: This endpoint will return the `vintrace_code` as the "crush\_site" value, and the **base** EUR (no vintage appended) as the "eur" value.

This endpoint uses JWT (JSON Web Token) Authentication. (Please see the "Authentication" section of the APIs documentation for instructions on how to receive a JWT)

\
At this endpoint, the user will be required to provide their credentials in the Header as `Authorization Bearer <JWT_Token_Retrieved_From_API_Login_Endpoint_Here>`

#### Query Parameters

| Name                 | Type      | Description                                                                                                                                                                                                                                                                                                                                                                                                                               |
| -------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| locations (optional) | String    | Comma-separated list of Vintrace location codes to filter response by specified locations (e.g., `?locations=US555,US444,US111`). If no value(s) are passed through, all locations will be returned.                                                                                                                                                                                                                                      |
| year                 | String    | Four digit year representing the Harvest Period that the data should represent (e.g., `?year=2022`). If no year is provided, the current year will be returned.                                                                                                                                                                                                                                                                           |
| lastUpdated          | timestamp | Timestamp denoting the date-time that should be used as the starting point for the records. Every record that has a Pick (with loads) or Load that has been created or updated since this time will be returned. (e.g., `?lastUpdated=2022-02-02 02:22:22` will return all records that have been created or updated since Feb 2, 2022 at 02:22:22). If no value is passed through, all records from one year ago today will be returned. |

#### Headers

| Name                                            | Type   | Description              |
| ----------------------------------------------- | ------ | ------------------------ |
| vino\_app<mark style="color:red;">\*</mark>     | String | mobile                   |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer \<JWT-TOKEN-HERE> |

{% tabs %}
{% tab title="200: OK A successful response will return a `200` status code and contain the following information:" %}

```javascript
{
    "message": "Successfully retrieved Harvest Scheduler Load details for Harvest Period {year} that have been updated since {lastUpdated}. {#} updated loads and {#} deleted load IDs were retrieved.",
    "current_loads": [
         {
             "id": 22,
             "quantity": 444,
             "receive_time": "02:00:00"
             "harvest_method": "Hand Picked",
             "bins": 3,
             "receive_area": "Plot 9",
             "hauler": "Biagioli",
             "block_id": 55,
             "block_code": "U5599",
             "block_name": "BIA.CH.22",
             "field_grade": "B",
             "appellation": "SMVL",
             "planning_region": "SLOC",
             "region": "CENTRAL COAST",
             "grower_name": "John Jacob",
             "rep_name": "Jingleheimer Smith",
             "varietal": "CHA",
             "farm_type": "Internal",
             "district_code": "03",
             "allocation_id": 77,
             "crush_site": "US555",
             "eur": "UNSHCHAOR",
             "current_estimate": 999,
             "pick_id": 88,
             "pick_date": "2022-07-07"
             "pick_quantity": 111,
             "pick_type": "Pick Called",
             "pick_manager": "Darlene Snell",
             "load_status": "Unconfirmed",
             "crush_site_receive_duration": 90,
             "bin_type": "1/2 Ton",
             "is_partial_load": 0,
             "requested_press": "Red Runner",
             "load_comments": [
                  "Look out for Pinot Grapes",
                  "Hauler could run into traffic. Allow for 30 extra minutes."
             ],
             "requested_receiving_vessels": [
                  "T76",
                  "T78",
             ]
         },
         {...},
         {...}
    ],
    "deleted_load_ids": [
         3,
         9
         22,
         111,
         354,
         777
    ]
}
```

{% endtab %}
{% endtabs %}
