LEX offers a comprehensive REST API to access data based on user permissions. This API provides more flexibility than the LEX user interface.
The LEX REST API supports extensive functions. Interactive API documentation is available.
Authentication
A small amount of information in the Livelihoods Explorer is not available publicly. This includes the list of specific community names and links to download the original BSS files. In order to access this information, users must be authenticated by logging in to the Livelihoods Explorer. After logging in, your browser will send a session cookie automatically to authenticate requests to the API.
If you do not authenticate or lack permission to access the data:
-
You may receive the error “no data found” when you query data that has restricted permissions.
-
Not all expected data may be included in the response.
API link structure
Each URL consists of up to 5 parts: the base URL, the endpoint, output format, filters, and fields.
Example:
https://livelihoodsdev.fews.net/api/season.html?country=ET&fields=simple
This URL has all 5 parts. It can be used to view a list of the seasons in the database for Ethiopia.
-
Base HEA database URL: https://livelihoods.fews.net/api/
-
Endpoint: season
-
Output format: .html
-
Filters: ?country=ET
-
Fields: &fields=simple
Base URL
The base URL for the Livelihoods Explorer API is https://livelihoods.fews.net/api/.
Endpoints
This API includes a number of endpoints.
The most useful endpoints for individuals doing data analysis are:
|
Name |
URL |
Description |
|---|---|---|
|
livelihoodactivitysummary |
View aggregated sums of calories and income from specific livelihood activities for Baseline Wealth Groups. Calculate the amount of overall income, expenditure, kcals_consumed and percentage_kcals
|
|
|
livelihoodzonebaseline |
Access spatial data of available livelihood zones for mapping. |
The most useful endpoints for individuals involved in gathering and submitting BSS data are:
|
Name |
URL |
Description |
|---|---|---|
|
classifiedproduct |
View a list of products in the database and their aliases. |
|
|
season |
View a list of seasons in the database. |
|
|
seasonalactivitytype |
View a list of the types of seasonal activities available in the database and their aliases. |
|
|
wealthcharacteristic |
View a list of wealth characteristics available in the database and their aliases. |
|
|
livelihoodcategory |
View a list of livelihood categories (e.g. Livelihood zone types) available in the database and their aliases. |
|
|
livelihoodproductcategory |
|
|
|
wealthgroupcategory |
View a list of wealth group categories available in the database and their aliases. |
|
|
hazardcategory |
View a list of hazard categories available in the database and their aliases. |
Additional endpoints include:
|
Name |
URL |
|---|---|
|
country |
|
|
currency |
|
|
unitofmeasure |
|
|
user |
|
|
userprofile |
|
|
sourceorganization |
|
|
livelihoodzone |
|
|
community |
|
|
wealthgroup |
|
|
baselinewealthgroup |
|
|
communitywealthgroup |
|
|
wealthgroupcharacteristicvalue |
https://livelihoods.fews.net/api/wealthgroupcharacteristicvalue/ |
|
baselinewealthgroupcharacteristicvalue |
https://livelihoods.fews.net/api/baselinewealthgroupcharacteristicvalue/ |
|
communitywealthgroupcharacteristicvalue |
https://livelihoods.fews.net/api/communitywealthgroupcharacteristicvalue/ |
|
livelihoodstrategy |
|
|
livelihoodactivity |
|
|
baselinelivelihoodactivity |
https://livelihoods.fews.net/api/baselinelivelihoodactivity/ |
|
responselivelihoodactivity |
https://livelihoods.fews.net/api/responselivelihoodactivity/ |
|
milkproduction |
|
|
butterproduction |
|
|
meatproduction |
|
|
livestocksale |
|
|
cropproduction |
|
|
foodpurchase |
|
|
paymentinkind |
|
|
relief |
|
|
fishing |
|
|
hunting |
|
|
wildfoodgathering |
|
|
othercashincome |
|
|
otherpurchase |
|
|
seasonalactivity |
|
|
seasonalactivityoccurrence |
https://livelihoods.fews.net/api/seasonalactivityoccurrence/ |
|
communitycropproduction |
|
|
communitylivestock |
|
|
marketprice |
|
|
seasonalproductionperformance |
https://livelihoods.fews.net/api/seasonalproductionperformance/ |
|
hazard |
|
|
event |
|
|
expandabilityfactor |
|
|
copingstrategy |
Output format
All endpoints support a standard range of extract formats, which can be accessed using an extension on the URL (for example, https://livelihoods.fews.net/api/livelihoodactivitysummary.html) or a query parameter (for example, https://livelihoods.fews.net/api/livelihoodactivitysummary/&format=json).
The standard values for the format parameter include:
-
html: a plain HTML table -
json: a JavaScript Object Notation text string -
csv: a UTF-8 comma-separated values file with a header row and a UTF-8 byte order mark (BOM) to enable Microsoft Excel and other tools to recognize the file correctly -
xml: an extensible markup language text string. XML is the recommended format for importing data into Microsoft Excel.
The livelihoodzonebaseline endpoint also supports spatial extracts using the geojson extract format.
Filters and pagination
Many of the time series data domains contain a large amount of data, such that attempting to extract all of it in a single request may fail due to browser timeouts. Best practice is to filter the request to include only the data that is required, or to use pagination to limit the size of each response.
Filters
Options for filters are unique to the end point. Some of the most common and/or useful filter options are described below. To view a full list of options for your endpoint, view our comprehensive, interactive API documentation.
-
Geography
-
country_code: The ISO 3166-1 alpha-2 two letter code for a country. Options can be found using https://livelihoods.fews.net/api/country/.
Example: &country_code=KE -
country: Similar to the country_code filter above, but uses the name of the country rather than the ISO code. This is easier to use, but may be slower, especially for large extracts. Example: ?country=Kenya -
livelihood_zone: A Livelihood Zone code such as ML12. Options can be found using https://livelihoods.fews.net/api/livelihoodzone/.
-
-
Livelihoods and Baselines
-
main_livelihood_category: The dominant pattern of livelihoods for a Livelihood Zone, such as pastoral or urban. Also called livelihood zone system or production system. Options can be found using https://livelihoods.fews.net/api/livelihoodcategory/. -
wealth_group_category: A Wealth Group Category such as Poor (P) or Better off (B/O). Options can be found using https://livelihoods.fews.net/api/wealthgroupcategory/. -
wealth_characteristic: An attribute of a Wealth Group such as the number of school-age children. Options can be found using https://livelihoods.fews.net/api/wealthcharacteristic/. -
strategy_type: A type of livelihood strategy, such as crop production. Options includeMilkProduction,ButterProduction,MeatProduction,LivestockSale,CropProduction,FoodPurchase,PaymentInKind,ReliefGiftOther,Hunting,Fishing,WildFoodGathering,OtherCashIncome,OtherPurchase. -
scenario: A Livelihood Activity contains the outputs of a Livelihood Strategy employed by one of the following:-
A Wealth Group in a Community in the reference year
-
A Wealth Group representing the Baseline as a whole in the reference year (the
baselinescenario) -
A Wealth Group representing the Baseline as a whole in response to a shock (the
responsescenario)
-
-
as_of_date: Usingas_of_dateequal to today will filter out Baselines that are no longer valid. Dates should be in the format YYYY-MM-DD. Example:as_of_date=2026-06-12.
-
-
Products
-
cpc: CPC is the UN’s Central Product Classification. CPC is a hierarchy, so specifying L02122AF will return only those matching records, whereas filtering for L02122 would return prices for both L02122AA and L02122AF. Options can be found using https://livelihoods.fews.net/api/classifiedproduct/
Example: ?cpc=L02122 -
product: A given product name or description. This is easier to use, but may be slower and less accurate than filtering using thecpc.
Example: ?product=maize
-
-
Seasonal calendars
-
season_type: The classification of a specific time of year based on weather patterns, temperature, and other factors. Options includeharvest,lean,wet,dry,mild,spring,summer,fall,winter, andmonsoon. -
activity_category: Types of seasonal activities. Options includeclimatology,stress_periods,crop,livestock,fishing,other_income, andother. -
seasonal_activity_type: A specific activity type such as weeding, harvesting, or births. Options can be found using https://livelihoods.fews.net/api/seasonalactivitytype/.
-
Pagination
When using JSON-formatted responses, the data can be paginated by passing page_size and offset parameters as part of the request.
For example a request for https://livelihoodsdev.fews.net/api/country.json?page_size=10&offset=0 will return the following response:
{
"count": 251,
"next": "https://livelihoodsdev.fews.net/api/country.json?offset=0&page=2&page_size=10",
"previous": null,
"results": [
<snip>
]
}
Fields
By default the API responses will contain a large number of fields. For some domains they may include various additional statistics such as the value one year ago or the five-year average. It is possible to control which fields are returned by the API using the fields parameter.
A reduced set of the commonly used fields can be selected using &fields=simple.
Alternatively, specific fields can be specified in a comma-separated list such as &fields=dataseries,start_date,period_date,value,two_year_average .
Ordering
Results can be ordered based on select fields. To order by a specific field, use &ordering=[field] such as &ordering=livelihood_zone. Default is to order ascending. To order descending, add a - before the field name such as &ordering=-livelihood_zone.
Additional support
The LEX REST API has a wide range of functionality. Comprehensive, interactive API documentation is available.
If your use case is not covered by our documentation, please contact Help Desk Support.