Filtering API Responses

Enterprise API endpoints accept filters, fields, and limit parameters to customize the data returned in the API response. When using these options, it is best to send requests using the POST method and include the parameters in the JSON request body. This page explains the correct placement, syntax, and available options, with examples of how to pass fields, filters, and limit in your requests. The following snippet is an example of a typical JSON request body.

{
  "filters": [
    {
      "field": "is_part_of.identifier", "value": "enwiki"
    }
  ],
  "fields": ["name","url","is_part_of"],
  "limit": 1
}

Fields

Important: By passing the fields parameter, you are specifying which fields to include exclusively. Only the field names you pass in the fields parameter will be returned by the API; fields not explicitly mentioned will not be returned in the API response

Use fields if you only want a specific set of fields and values returned in the API response, such as article names or category URLs.

The fields parameter takes an array of comma-separated values as input. Specify fields using dot notation. Any field in the API Response can be specified with fields: Objects such as version, arrays such as version.tags, or fields with a single value such as version.is_minor_edit. The Data Dictionary lists all the fields present in Enterprise API Responses.

Example POST request using cURL to call the available Snapshots and only return the identifier info, date modified, and size of the snapshot:

curl --location 'https://api.enterprise.wikimedia.com/v2/snapshots' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--data '{
 "fields": ["is_part_of.identifier", "date_modified", "size.value"]
}'

Filters

Important: By passing the filters parameter, you are filtering in, or filtering down, to a specific subset of Wikimedia data. If you specify "field":"is_part_of.identifier", "value":"enwiki" as a filter, the API will only return data from English Wikipedia, and not from any other Wikimedia projects or languages.

Use filters when you need to retrieve data from a specific range of values, such as data from a specific project, language, or namespace. 

The filters parameter takes an array of objects as input. Every field specified in filters can only have one value associated with it. Only fields with a single value can be used in filters, e.g. "field":"version.is_minor_edit", "value":true. You cannot specify arrays (e.g. “version.tags“), or objects (e.g. “version“). Required fields can always be specified. Fields that are strings, integers, floats, and booleans can be used with filters. The Data Dictionary lists all the fields present in Enterprise API Responses.

Example POST request using cURL to request all article data for “Marie Curie” in French:

curl --location 'https://api.enterprise.wikimedia.com/v2/articles/Marie_Curie' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--data '{
  "filters": [
    {
      "field":"in_language.identifier", "value": "fr"
    }
  ]
}'

Limit

Set a limit to restrict the number of articles returned in an API response. The default value for limit is 3, and its maximum value is 10. Limit can only be used with On-demand endpoints.

Example of an On-demand API POST call that limits the number of articles returned for the Wikipedia article NATO (which has almost 200 different languages) to 1:

curl --location 'https://api.enterprise.wikimedia.com/v2/articles/NATO' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--data '{   
  "limit": 1  
}'