MoroccoAPIDocumentation
API reference

Choose a resource. Set the parameters. Try it.

No API keyJSON responsesOpen CORS

Search postal codes

GET/api/v2/postal-codes

Good to know. Poste Maroc snapshot from September 2018; may be outdated. 45 suspicious rows excluded. A place can have several codes.

Provide at least one filter: q, region_code, province_code or city.

Understand the context

A postal code routes mail; an HCP code identifies an administrative area. A city can have several postal codes, one for each neighborhood. This file describes September 2018.

Parameters

07
stringOptional · Query

Search text, at least 2 characters.

2-100 characters
stringOptional · Query

Resource type.

stringOptional · Query

MoroccoAPI region code.

stringOptional · Query

MoroccoAPI province or prefecture code.

stringOptional · Query

One of /postal-codes/cities, ignoring case, accents, spaces and hyphens.

2-100 characters
integerOptional · Query

Results per page. Default 100, maximum 500.

Minimum: 1Maximum: 500Default: 100
integerOptional · Query

Matching results to skip. Starts at 0.

Minimum: 0Maximum: 2147483647Default: 0
Read the response

data: The requested results, as an object or an array.

meta: Dataset sources, license and dates. null means unknown or unavailable.

meta.pagination: Lists: 100 results by default, 500 maximum. Use limit and offset; meta.pagination.next_offset is null on the last page.

Illustrative example: With limit=10 and offset=0, the first page holds at most 10 results. If next_offset is 10, request the next page with offset=10 and the same filters. Stop when next_offset is null.

API v2 is the canonical path. Older /api/v1 paths remain compatibility aliases for the currently published behavior, including pagination; no removal date is scheduled.

Response fields 8

[] means each item in a list. null means unknown or unavailable, never zero. The guide language does not translate source values.

dataobject[]

Requested result: a single object or a list.

data[].postal_codestring

Five-digit postal code, kept as text; separate from an HCP administrative code.

data[].typestring

locality: a single-code place outside multi-code cities; neighborhood: a district in a city with several postal codes.

Accepted values: "locality" "neighborhood"

data[].namestring

Resource name, grouped by language where applicable.

data[].citystring | null

Multi-code city containing the neighborhood; null for a standalone locality.

data[].province_codestring

Identifier of the parent province or prefecture, below the region.

data[].region_codestring

Identifier of the parent region, Morocco’s first administrative level.

data[].commune_codestring | null

Exact locality-name match to a commune in the same province. null without a match and for every neighborhood.

Data structure
{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "data",
    "meta"
  ],
  "properties": {
    "data": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "postal_code",
          "type",
          "name",
          "city",
          "province_code",
          "region_code",
          "commune_code"
        ],
        "properties": {
          "postal_code": {
            "type": "string",
            "pattern": "^[0-9]{5}$"
          },
          "type": {
            "type": "string",
            "enum": [
              "locality",
              "neighborhood"
            ],
            "description": "locality: a place outside the multi-code cities, with one code. neighborhood: a neighbourhood of a multi-code city."
          },
          "name": {
            "type": "string",
            "description": "Poste Maroc spelling, preserved apart from whitespace."
          },
          "city": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "string",
                "nullable": true,
                "enum": [
                  null
                ]
              }
            ],
            "description": "Multi-code city of a neighborhood, or null for a locality."
          },
          "province_code": {
            "type": "string"
          },
          "region_code": {
            "type": "string"
          },
          "commune_code": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "string",
                "nullable": true,
                "enum": [
                  null
                ]
              }
            ],
            "description": "MoroccoAPI commune whose name equals the locality name in the same province. Null when there is no exact match, and always null for neighborhoods."
          }
        }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "dataset",
        "total",
        "license",
        "retrieved_at",
        "transformation_version",
        "sources",
        "pagination"
      ],
      "properties": {
        "dataset": {
          "enum": [
            "postal-codes"
          ]
        },
        "total": {
          "type": "integer",
          "minimum": 0
        },
        "license": {
          "enum": [
            "ODbL-1.0"
          ]
        },
        "retrieved_at": {
          "enum": [
            "2026-10-14"
          ]
        },
        "transformation_version": {
          "enum": [
            "1.1.0"
          ]
        },
        "sources": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "dataset",
              "producer",
              "source_url",
              "resource_url",
              "license",
              "source_updated_at"
            ],
            "properties": {
              "dataset": {
                "type": "string"
              },
              "producer": {
                "type": "string"
              },
              "source_url": {
                "type": "string",
                "format": "uri"
              },
              "resource_url": {
                "type": "string",
                "format": "uri"
              },
              "license": {
                "enum": [
                  "ODbL-1.0",
                  "CC-BY-4.0"
                ]
              },
              "source_updated_at": {
                "type": "string",
                "format": "date"
              }
            }
          }
        },
        "pagination": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "limit",
            "offset",
            "count",
            "has_more",
            "next_offset"
          ],
          "properties": {
            "limit": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            },
            "offset": {
              "type": "integer",
              "minimum": 0,
              "maximum": 2147483647
            },
            "count": {
              "type": "integer",
              "minimum": 0,
              "maximum": 500
            },
            "has_more": {
              "type": "boolean"
            },
            "next_offset": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 2147483647
                },
                {
                  "type": "string",
                  "nullable": true,
                  "enum": [
                    null
                  ]
                }
              ]
            }
          }
        }
      }
    }
  }
}
Sources and pagination 19
metaobject

Result context: sources, dates, license and pagination where applicable.

meta.datasetstring

Name of the dataset for this result or source.

Accepted values: "postal-codes"

meta.totalinteger

Number of matching records before pagination; not the size of this page.

meta.licensestring

Reuse license. mixed means licenses differ: inspect each source.

Accepted values: "ODbL-1.0"

meta.retrieved_atstring

Date the project retrieved the source file; not the observation date.

Accepted values: "2026-10-14"

meta.transformation_versionstring

Version of the dataset conversion rules; separate from the API version.

Accepted values: "1.1.0"

meta.sourcesobject[]

Sources used for this result, with their publishers and licenses.

meta.sources[].datasetstring

Name of the dataset for this result or source.

meta.sources[].producerstring

Organization publishing the original data.

meta.sources[].source_urlstring

Source publication or dataset landing page.

meta.sources[].resource_urlstring

Link to the actual file or resource used.

meta.sources[].licensestring

Reuse license. mixed means licenses differ: inspect each source.

Accepted values: "ODbL-1.0" "CC-BY-4.0"

meta.sources[].source_updated_atstring

Last update reported by the source; not the retrieval date.

meta.paginationobject

Information for reading a collection one page at a time.

meta.pagination.limitinteger

Requested maximum records per page: default 100, maximum 500.

meta.pagination.offsetinteger

Matching records skipped before this page, after filtering. The first page starts at 0.

meta.pagination.countinteger

Number of records actually returned on this page.

meta.pagination.has_moreboolean

true when another page of records remains.

meta.pagination.next_offsetinteger | null

Use as offset for the next page; null at the end. Keep the same filters.

Errors
  • 400: Invalid or missing parameter.

Errors return error.code, error.message and error.request_id.

errorobject

Details of a failed request; replaces data and meta.

error.codestring

Stable error code, such as RESOURCE_NOT_FOUND; use it in application logic.

error.messagestring

Human-readable error explanation; use code for application logic.

error.request_idstring

Identifier for this request, useful when reporting a problem.

Your request

GET · JSON

Base URL

Response

The live response will appear here.

Language changes the guide, not JSON keys or source values.