Sorting

Once a user has data from My Market News, they will need to sort it. The MyMarketNews API provides the ability to sort and/or filter data. The sort feature allows user the ability to manipulate data using conditions. By default, data is sort automatically by report date in descending order. 

Default Sorting

EXAMPLE: Default Sorting

cURL: curl https://marsapi.ams.usda.gov/services/v1.2/reports/1095 -u api_key:
JSON: https://marsapi.ams.usda.gov/services/v1.2/reports/1095

The output of the API will be sorted by report_date in descending order:

EXAMPLE Response:

{
    "results": [
        {
            "report_begin_date": "2018-01-08",
            "report_end_date": "2018-01-08",
            "published_date": "2018-01-31",
            "office_name": "Madison",
            "office_code": "DA-MD",
            "office_city": "Madison",
            "office_state": "WI",
            "market_location_name": "National Cold Storage",
            "market_location_city": "",
            "market_location_state": "WI",
            "group": null,
            "category": "Hard Products",
            "commodity": "Cheese",
            "market_type": "Cold Storage",
            "market_type_category": "Dairy Market",
            "slug_id": "1095",
            "slug_name": "MD_DA953",
            "community": "Dairy",
            "quality": "N/A",
            "holdings_unit": "LBS",
            "holdings_current_lbs": "96009227",
            "holdings_1stDayMTH_lbs": "96245049",
            "holdings_change_lbs": "-235822",
            "holdings_change_percent": "0.0000",
            "currentMTH_1stDay": "2018-01-01",
            "report_narrative": null,
            "commodity_narrative": null,
            "special_announcement": null
        }

Sorting with Single Fields

The MyMarketNews API provides the ability to sort response data based on data elements available in the response data set. Keyword sort informs the API that the user is requesting the response to be sorted. When sorting by the response fields, a user should only pick the fields which are available in the response such as category, office_name, or commodity.  

EXAMPLE: Sort by Category in Ascending Order

Syntax: sort = category

cURL: curl https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=category -u api_key:
JSON: https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=category

EXAMPLE: Sort by Category in Descending Order

Syntax: sort = -category

cURL: curl https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=-category -u api_key:
JSON: https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=-category

Sorting with Multiple Fields:

EXAMPLE: Sort by Category and Commodity, Ascending 

Syntax: sort = category, commodity

cURL: curl https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=category,commodity -u api_key:
JSON: https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=category,commodity

EXAMPLE: Sort by Category and Commodity, Descending 

Syntax: sort = -category, -commodity

cURL: curl https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=-category,-commodity -u api_key: 
JSON: https://marsapi.ams.usda.gov/services/v1.2/reports/1095?sort=-category,-commodity