New Zealand Legislation API (v0)

Download OpenAPI specification:

Introduction

This API provides progammatic access to New Zealand legislation. It is currently "Version Zero" of an API, which has been developed to provide an opportunity for developers to test and provide feedback which will inform future enhancement and refinement.

The functionality of the API is intended to match that of the site search on the Legislation Website, and is strongly influenced by the FRBR model.

Conceptual model

This API is based on a three-tier conceptual model of works, versions, and formats.

A work is the highest level, and represents the concept of an enduring standalone piece of legislation, that may have multiple versions. Each work has a work_id. Examples of works are:

  • New Zealand Bill of Rights Act 1990, act_public_1990_109
  • Natural and Built Environment Bill, bill_government_2022_186
  • Microwave Ovens Regulations 1982, secondary-legislation_pco-drafted_1982_221

One level below a work is a version. Each work can have one or more versions. Each consolidation of an Act is a new version, as is each stage of a Bill. A version is equivilant to an expression in the FRBR model. Each version has a version_id. Examples of versions are:

  • The version of the New Zealand Bill of Rights Act 1990 as at 30 August 2022, act_public_1990_109_en_2022-08-30
  • The second reading version of the Natural and Built Environment Bill as reported from the Environment Committee on 27 June 2023, bill_government_2022_186_en_2023-06-27
  • The version of the Microwave Ovens Regulations 1982 as at 1 July 2023, secondary-legislation_pco-drafted_1982_221_en_2013-07-01

One level below a version is a format. Each version of each work will have multiple formats, such as the source XML file, a PDF file, or an HTML page. Some versions will have formats that other versions don't have, such as the as enacted versions of some Acts which have also have a format providing a scan of the original printed Act. A format is equivilant to a manifestation in the FRBR model.

This API does not include an equivilant of the fourth level in the FRBR model, 'Item', which would generally be the concrete example of a specific format of a version, i.e. an XML file saved on a particular drive, or a PDF file printed on sheets of paper.

Identifiers

The structure of work_id and version_id identifiers used by this API is shared with the URLs of the Legislation website. They are constructed from six segments:

  1. type — Kind of legislation. Must be one of: act, bill, secondary-legislation, amendment-paper.

  2. subtype — Sub-classification of that type. Allowed values depend on type:

    • Acts: public, imperial, local, private, provincial
    • Bills: government, local, members, private
    • Secondary legislation: agency-drafted, pco-drafted
    • Amendment papers: government, members
  3. date — Year. Must be four digits (YYYY). May be prefixed with ~ when the value is ephemeral.

  4. number — Legislation number or identifier. Must match: digits. May have followed by a single letter (deduplication), optionally followed by a hyphen and letter (e.g. bill split: 96-B). May be prefixed with ~ when ephemeral.

  5. language — Language. Currently only en is used.

  6. version_date — Date identifying the version in time. Must be YYYY-MM-DD. May be prefixed with ~ when ephemeral. May have a suffix of one or more deduplication letters (e.g. A, B, AB, BA, 2023-12-31B) when multiple versions share the same base date.

A version_id is all six segments, and a work_id is the first four segments, each joined together with underscore characters.

Ephemeral segments

For some agency-published secondary legislation harvested from agency websites through the pilot secondary legislation service, we do not have sufficient data to construct a permanent identifier. In these cases, we use fallback values to calculate 'ephemeral' identifiers.

For example, if we do not know the commencement date of a piece of secondary legislation, we cannot determine the correct value for the version_date segment, and will fall back to using the date the record was harvested from the agency website.

To indicate that these values are not final, and may change if we get better data for the record in the future, they are prefixed with a ~ character. Any identifiers which contain ~ characters may change in the future.

URLs

Website URLs for legislation follow the same pattern as the identifiers described above:

https://www.legislation.govt.nz/{type}/{subtype}/{date}/{number}/{language}/{version_date}/

The website uses latest as an alias value in the version_date segment, which always resolves to the most recent version of a work.

Formats

Responses to API queries include links to versions in their available formats. These can also be constructed directly by manipulating URLs, for example:

For legislation and secondary legislation drafted by the PCO; html, pdf, and xml formats are available.

For as enacted versions of pre-2008 Acts that have been converted from scans of the original printed volumes, an additional format of pdf_original_scan is available which contains the scanned PDF.

For agency drafted secondary legislation harvested through the pilot secondary legislation service, HTML or PDF formats may be available, but this will vary from record to record, and links may point to agency websites which do not follow the URL patterns described above.

Rate limiting

Each API key has a default rate limit of 10,000 requests per day, with the quota resetting at midnight NZ local time.

Requests sent after this rate limit has been reached will receive a response with HTTP status code 429, Too Many Requests.

The rate limit is communicated using the X-RateLimit response headers, which have values of:

  • X-RateLimit-Limit: number of requests permitted per period.
  • X-RateLimit-Remaining: number of requests remaining in the current period.
  • X-RateLimit-Reset: Unix timestamp of the UTC time at which the period ends and the quota resets.

In addition to these per-key rate limits, there is a burst limit of no more than 2,000 requests permitted from any single IP address in any five minute period. Requests sent after this limit is reached will receive a response with HTTP status code 403 Forbidden. Once a further five minutes have elapsed, further requests from that IP address will be permitted.

search

search

query Parameters
api_key
string

API Key for authentication (can also be passed via X-Api-Key header)

search_term
string

Search term to filter results

search_field
string

Field to search in (title or fulltext)

legislation_status
string

Filter by legislation status

legislation_type
string

Filter by legislation type

header Parameters
X-Api-Key
string

API Key for authentication (can also be passed via api_key query parameter)

Responses

works

works/{work_id}/versions/

path Parameters
work_id
required
string
query Parameters
api_key
string

API Key for authentication (can also be passed via X-Api-Key header)

header Parameters
X-Api-Key
string

API Key for authentication (can also be passed via api_key query parameter)

Responses

works/

Search for works.

This endpoint is the main entry to the API, and mirrors the functionality of the website site search. Searches can be either title or content searches, and results are a series of works that match the search query.

Each work has a latest_matching_version key with details of the newest version of the work that the search term was found within. This may not be the same version as the newest version of the work, for example if you perform a content search for a phrase that appears in an older version of an Act in a section which has since been repealed and does not appear in newer versions. Inside the latest_matching_version object is a key is_latest_version which gives a boolean value for whether the version described in latest_matching_version is the actually newest version of that work.

The work_id of each work returned can be passed to the /works/{work_id}/versions endpoint to get all versions of that work, and any version_id can be passed to the /versions/{version_id} endpoint to get details of that specific version.

query Parameters
api_key
string

API key for authentication. Can also be passed via X-Api-Key header.

search_term
string

What to search for.

The supplied phrase will be searched in either work titles or work content depending on the value of the search_field parameter.

Stemming is enabled by default, i.e. 'levy' will return matches for both 'levy' and 'levies'. To disable stemming for a word or phrase, wrap it in " charcters.

The search term is processed by ElasticSearch as a 'Simple query string query'. For full details on this syntax, see the ElasticSearch docs.

search_field
string
Enum: "title" "content"

Whether to perform a title search of content search.

page
integer
Default: 1

Which page of results to receive, for responses where there are more results returned than the per_page value, and the response does not contain all results.

per_page
integer
Default: 20

How many results to receive in a single response. Default is 20, maximum is 100.

legislation_status
string
Enum: "in_force" "not_in_force" "no_value"

Filter to specific legislation status.

legislation_type
string
Enum: "act" "amendment_paper" "bill" "secondary_legislation"

Filter to a specific legislation type.

act_type
string
Enum: "public" "private" "imperial" "local" "provincial"

Filter to a specific type of Act. Should only be supplied if legislation_type = act is also supplied.

act_classification
string
Enum: "principal" "amendment"

Filter to a specific classification of Act. Should only be supplied if legislation_type = act is also supplied.

act_status
string
Enum: "in_force" "not_in_force" "repealed"

Filter to a specific status of an Act. Should only be supplied if legislation_type = act is also supplied.

instrument_type_group
string
Enum: "regulations" "order" "rules" "code" "bylaws" "determination" "exemption" "notice" "instrument" "other_type"

Filter to a specific type of secondary legislation. Should only be supplied if legislation_type = secondary_legislation is also supplied.

instrument_status
string
Enum: "expired" "in_force" "not_yet_in_force" "revoked" "superseded"

Filter to a specific status of secondary legislation. Should only be supplied if legislation_type = secondary_legislation is also supplied.

instrument_classification
string
Enum: "principal" "amendment"

Filter to a specific classification of secondary legislation. Should only be supplied if legislation_type = secondary_legislation is also supplied.

bill_type
string
Enum: "government" "local" "member" "private"

Filter to a specific type of Bill. Should only be supplied if legislation_type = bill is also supplied.

bill_status
string
Enum: "current" "enacted" "terminated"

Filter to a specific status of Bill. Should only be supplied if legislation_type = bill is also supplied.

administering_agencies
string

Filter to a specific administering agency. The value must be the full text name, exactly as listed on the browse agencies page.

sort_by
string
Enum: "title_asc" "title_desc" "year_asc" "year_desc" "most_recently_updated"

How to sort the results. Options are:

  • title_asc: Sort alphabetically by title, A-Z.
  • title_desc: Sort alphabetically by title, Z-A.
  • year_asc: Sort by legislative year and number, oldest to newest. Agency secondary legislation which does not have legislative year and number may not be meaningfully sorted.
  • year_desc: Sort by legislative year and number, newest to oldest. Agency secondary legislation which does not have legislative year and number may not be meaningfully sorted.
  • most_recently_updated: Sort by the most recent version date of each work, newest to oldest.
publisher
string
Enum: "Agency" "Parliamentary Counsel Office"

Filter to works published by PCO (all Acts, Bills, Amendment papers, and PCO-drafted secondary legislation) with a value of Parliamentary Counsel Office, or Agency-published secondary legislation harvested through the pilot secondary legislation service with a value of Agency.

header Parameters
X-Api-Key
string

API key for authentication. Can also be passed via api_key query parameter.

Responses

Response samples

Content type
application/json
{
  • "results": [
    ],
  • "page": 0,
  • "per_page": 0,
  • "total": 0
}

works/{work_id}/versions/

Get all versions of a specified work.

path Parameters
work_id
required
string

The ID of the work to return versions of.

query Parameters
api_key
string

API key for authentication. Can also be passed via X-Api-Key header.

sort
string
Default: "desc"
Enum: "asc" "desc"

How to sort the results.

header Parameters
X-Api-Key
string

API key for authentication. Can also be passed via api_key query parameter.

Responses

Response samples

Content type
application/json
{
  • "results": [
    ],
  • "page": 0,
  • "per_page": 0,
  • "total": 0
}

versions

versions/{version_id}/versions/

Get details of a specific version of a work.

path Parameters
version_id
required
string
query Parameters
api_key
string

API key for authentication. Can also be passed via X-Api-Key header.

header Parameters
X-Api-Key
string

API key for authentication. Can also be passed via api_key query parameter.

Responses

Response samples

Content type
application/json
{
  • "title": "string",
  • "version_id": "string",
  • "work_id": "string",
  • "legislation_status": "string",
  • "legislation_type": "string",
  • "administering_agencies": [
    ],
  • "act_type": "string",
  • "act_status": "string",
  • "instrument_type_group": "string",
  • "instrument_status": "string",
  • "instrument_classification": "string",
  • "bill_type": "string",
  • "bill_status": "string",
  • "formats": [
    ]
}