# Including Related Data

Some search endpoints support an `include` query parameter that lets you fetch related data in a single request, avoiding extra API calls. Without `include`, related properties are **omitted entirely** from the response. With it, the requested relationships are populated inline.

***

## Syntax

Pass a comma-separated list of relationship names as the `include` query parameter:

```
GET /{resource}/search?q=<query>&include=<relationship1>,<relationship2>
```

Values are **case-sensitive** and must match the relationship names documented for each endpoint. Unrecognized values are silently ignored.

***

## Supported Endpoints

### GET /orders/search

**API:** Internal API

| Relationship   | Description                                                             |
| -------------- | ----------------------------------------------------------------------- |
| `lineItems`    | Line item details for each order (part number, quantity, price, status) |
| `shippingInfo` | Shipping details for each order (address, carrier, service level)       |

**Without `include`** — `lineItems` and `shippingInfo` are not present in the response:

```json
{
  "data": {
    "orders": [
      {
        "orderId": 5499760,
        "companyId": 12345,
        "requesterId": 500,
        "poNumber": "PO-456",
        "requesterName": "Jane Smith",
        "statusName": "Processing",
        "createdTimestamp": "2026-01-15T10:30:00Z"
      }
    ],
    "pagination": { "total": 1, "limit": 50, "offset": 0, "hasMore": false }
  }
}
```

**With `include=lineItems,shippingInfo`:**

```bash
curl -G "https://api.partssource.com/internal/api/orders/search" \
  -H "Authorization: Bearer <token>" \
  -H "x-api-key: <key>" \
  --data-urlencode 'q=companyId:12345 AND createdDate>="2026-01-01"' \
  -d "include=lineItems,shippingInfo" \
  -d "limit=20"
```

```json
{
  "data": {
    "orders": [
      {
        "orderId": 5499760,
        "companyId": 12345,
        "requesterId": 500,
        "poNumber": "PO-456",
        "requesterName": "Jane Smith",
        "statusName": "Processing",
        "createdTimestamp": "2026-01-15T10:30:00Z",
        "lineItems": [
          {
            "lineItemId": 9000001,
            "partNumber": "MOT-1234",
            "requestedPartNumber": "MOT-1234-A",
            "description": "Replacement motor assembly",
            "quantity": 1,
            "price": 249.99,
            "extendedPrice": 249.99,
            "statusName": "Processing"
          }
        ],
        "shippingInfo": [
          {
            "shippingDocId": 7000001,
            "lineItemIds": [9000001],
            "attentionTo": "Jane Smith",
            "address1": "100 Medical Center Dr",
            "city": "Aurora",
            "state": "IL",
            "zip": "60505",
            "country": "US",
            "carrierName": "FedEx",
            "serviceLevel": "Ground"
          }
        ]
      }
    ],
    "pagination": { "total": 1, "limit": 50, "offset": 0, "hasMore": false }
  }
}
```

You can include one or both relationships:

```
GET /orders/search?q=companyId:12345&include=lineItems
GET /orders/search?q=companyId:12345&include=shippingInfo
GET /orders/search?q=companyId:12345&include=lineItems,shippingInfo
```

***

## Performance Considerations

Including related data increases response size and may add latency. Only request relationships you need. For large result sets, consider:

* Using a narrower search query to reduce the number of orders returned
* Reducing the `limit` parameter when including related data
* Omitting `include` when you only need order-level summary information
