Distinct Parameter

lgfapi supports the "distinct" query parameter for GET requests when querying with values_list style GET request. Values list requests are used for making more direct calls to fetch targeted relational table data without the structure of an entity serializer. Due to this, there may be instances where the resultant data is repeated. For example: An OBLPN may have multiple allocation records pointing back to multiple order details for the same order. A values list request for the order_nbr would have as many repeated results as allocation records. This follows the same principles as the underlying DB query.

Assumptions

  • Only works for GET requests using the values_list and ordering query parameter
  • Only works for list-style (paginated) requests. Will not work when querying by id.
  • If used in unsupported situations, the parameter will be ignored (no error).
Note: When using distinct parameter, you must provide the ordering parameter in the URL path to get unique records in response. In the ordering parameter, use the distinct value that is you have provided in the values_list parameter.

Example Usage - List (Paginated) Response

Example 1

URL to fetch order_nbr without using distinct

GET .../entity/order_dtl/?order_id=123&values_list=order_id,order_id__order_nbr:order_nbr

Response



{
    "result_count": 2,
    "page_count": 1,
    "page_nbr": 1,
    "next_page": null,
    "previous_page": null,
    "results": [
        {
            "order_id": 123,
            "order_nbr": "ORDER123"
        },
        {
            "order_id": 123,
            "order_nbr": "ORDER123"
        },
    ]
}

URL to fetch unique order_nbr using distinct

GET ...wms/lgfapi/v10/entity/order_dtl/?order_id=123&values_list=order_id,order_id__order_nbr:order_nbr&ordering=order_id__order_nbr&distinct=1

Response



{
    "result_count": 1,
    "page_count": 1,
    "page_nbr": 1,
    "next_page": null,
    "previous_page": null,
    "results": [
        {
            "order_id": 123,
            "order_nbr": "ORDER123"
        }
    ]
}

Example 2

URL to get unique container status for each of the first 100 containers selected using distinct parameter.

GET ...wms/lgfapi/v10/entity/container/?limit=100&values_list=status_id__description:container_status&ordering=status_id__description&distinct=true

Response



{
    "result_count": 4,
    "page_count": 1,
    "page_nbr": 1,
    "next_page": null,
    "previous_page": null,
    "results": [
        {
            "container_status": "Allocated"
        },
        {
            "container_status": "Cancelled"
        },
        {
            "container_status": "Consumed"
        },
        {
            "container_status": "Delivered"
        }
    ]
}

Example 3

URL to get unique locations based on the selected query parameters such as status, faility, company, history activity for the Inventory history entity using distinct parameter.

GET ...wms/lgfapi/v10/entity/inventory_history/?status_id__in=0,10,20,90,99,101&facility_id=648&company_id=369&history_activity_id__in=49&lock_code=SL&create_ts__month=05&values_list=location&ordering=location&distinct=true

Response


{
    "result_count": 4,
    "page_count": 1,
    "page_nbr": 1,
    "next_page": null,
    "previous_page": null,
    "results": [
        {
            "location": "AC-1-KB-23"
        },
        {
            "location": "AC9-22-5-2-1"
        },
        {
            "location": "AC9-22-9-1-1"
        },
        {
            "location": "ACSM90500-002-B2-L02"
        }
    ]
}

Retrieve (Single-Object) Response

Flow where entity "id" is included as part of the URL.

This is not supported. Since this GET request style will always return a single object representation, there is no meaning to "distinct" as values cannot be repeated. If the query parameter is included in this flow, it will be ignored.