# Get inventory transactions

This method allows a customer to retrieve inventory transactions.
Inventory transactions include Sales Orders, Purchase Orders, Transfer In,
Transfer Out, Production Lines, Inventory Adjustments and Inventory Status
Changes. There are multiple input filters available for use, including filters
to retrieve specific types of inventory transactions, to retrieve transactions
processed on a particular date, or to retrieve transactions in a specific
Wineshipping warehouse. There are also pagination and skip/top query parameters
that allow customers to further control the inventory transactions that are
returned in the response.
**Date range:** For timely execution, retrieve no more than 3 months of data
at a time, using `TransactionStartDateTime` and `TransactionEndDateTime`.
**Example: get the last 3 months of inventory transactions (JavaScript)**
The script requests the last 3 months in consecutive 1-month windows and pages
through each window with `Skip` and `Top`.

```javascript
const BASE_URL = 'https://api.wineshipping.com/v3';
const AUTH = {
  UserKey: 'YOUR_USER_KEY',
  Password: 'YOUR_PASSWORD',
  CustomerNo: 'YOUR_CUSTOMER_NO',
};
const PAGE_SIZE = 500;

// Returns a new Date moved by the given number of months (UTC).
function addMonths(date, months) {
  const result = new Date(date);
  result.setUTCMonth(result.getUTCMonth() + months);
  return result;
}

// Fetches every page of transactions for one date window.
async function getTransactionsForWindow(start, end) {
  const transactions = [];
  let skip = 0;
  let moreRecords = true;
  while (moreRecords) {
    const response = await fetch(`${BASE_URL}/api/Inventory/GetTransactions`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        Authentication: AUTH,
        TransactionStartDateTime: start.toISOString(),
        TransactionEndDateTime: end.toISOString(),
        Skip: skip,
        Top: PAGE_SIZE,
      }),
    });
    if (!response.ok) {
      throw new Error(`GetTransactions failed (${response.status}): ${await response.text()}`);
    }
    const result = await response.json();
    transactions.push(...(result.InventoryTransactions ?? []));
    moreRecords = result.MoreRecords;
    skip += PAGE_SIZE;
  }
  return transactions;
}

async function getTransactionsForLookback() {
  const now = new Date();
  const threeMonthsAgo = addMonths(now, -3);
  const transactions = [];

  // Walk the lookback period in consecutive windows of 1 month.
  for (let start = threeMonthsAgo; start < now; ) {
    const end = new Date(Math.min(addMonths(start, 1).getTime(), now.getTime()));
    transactions.push(...(await getTransactionsForWindow(start, end)));
    start = end;
  }
  return transactions;
}

getTransactionsForLookback()
  .then((transactions) => console.log(`Total transactions: ${transactions.length}`))
  .catch((error) => console.error(error));
```

Endpoint: POST /api/Inventory/GetTransactions
Version: 3.1.4

## Request fields (application/json):

  - `Authentication` (object, required)
    Credentials are required for all API operations.

  - `Authentication.UserKey` (string, required)
    Example: C445598CB576468EA35FBB22C55584EF

  - `Authentication.Password` (string, required)
    Example: AF63FDAC1E704DC1AC9460F669ABF107

  - `Authentication.CustomerNo` (string, required)
    Example: 10703

  - `TransactionDate` (string)
    Required unless `TransactionStartDateTime` is specified. Format: MM/DD/YYYY
    Example: 12/31/2025

  - `TransactionStartDateTime` (string)
    Required unless `TransactionDate` is specified.
    Example: 2026-02-10T08:12:39.483Z

  - `TransactionEndDateTime` (string)
    Required when `TransactionStartDateTime` is specified. Note: For timely execution, please ensure that no more than 3 months of data is retrieved at a time.
    Example: 2026-02-10T08:12:39.483Z

  - `TransactionType` (string)
    Required unless `TransactionTypes` is specified instead

  - `TransactionTypes` (array)
    Required unless `TransactionType` is specified instead

  - `Warehouse` (string)
    See [warehouse locations](../../../../docs/codes/warehouselocations) for possible values.
    Enum: "APC01", "APC02", "COB01", "COB02", "ETC01", "MMC01", "PRB02", "PRB04", "SJU01", "TWL01", "VCX01", "WOX01"

  - `Warehouses` (array)
    (COMING SOON)

  - `Reference` (string)
    This field contains [Inventory Transaction Reference Codes](https://developer.wineshipping.com/../../../../docs/v3/ZG9jOjE4NTY4NjU2-codes-and-descriptions#inventory-transaction-reference-codes) that explain why a transaction occurred

  - `InventoryStatus` (string)
    See [inventory codes](../../../../docs/codes/inventorycodes) for possible values. Array of up to 5 items is allowed, and if omitted, all items will be included in the results.
    Enum: "GOOD-NO-TX", "RTGD-NO-TX", "RDMG-NO-TX", "CDMG-NO-TX", "DMGD-NO-TX", "GOOD-NO-BD", "DMGD-ST-BD", "GOOD-ST-IM"

  - `InventoryStatuses` (array)
    (COMING SOON)

  - `ItemNumbers` (array)

  - `Skip` (integer)

  - `Top` (integer)

## Response 200:

  - `200` (unknown)
    OK

## Response 200 fields (application/json):

  - `TransactionReferenceNumber` (string)

  - `TotalRecordCount` (integer)

  - `Skip` (integer)

  - `Top` (integer)

  - `MoreRecords` (boolean)

  - `InventoryTransactions` (array)

  - `InventoryTransactions.ItemNo` (string)

  - `InventoryTransactions.ItemDescription` (string)

  - `InventoryTransactions.ItemUnit` (string)

  - `InventoryTransactions.AlcoholPercentage` (string)

  - `InventoryTransactions.Warehouse` (string)

  - `InventoryTransactions.InventoryStatus` (string)

  - `InventoryTransactions.TransactionDate` (string)
    Example: 1/1/2025

  - `InventoryTransactions.TransactionDateTime` (string)
    The date and time of the inventory transaction in ISO 8601 format. At present the time component is not used and will always be set to 00:00:00.000Z, but this may change in the future.
    Example: 2026-01-01T00:00:00.000Z

  - `InventoryTransactions.TransactionType` (string)

  - `InventoryTransactions.Reference` (string)

  - `InventoryTransactions.PONumber` (string)

  - `InventoryTransactions.ShipToName` (string)

  - `InventoryTransactions.OrderType` (string)

  - `InventoryTransactions.Quantity` (integer)

## Response 404:

  - `404` (unknown)
    No content matched the requested input criteria

