Range Grande-Bretagne

Bêta

Return full postcodes in England within range of a postcode or settlement.

Référence OpenAPI
GEThttps://api.pro6pp.nl/v2/range/gb

Vue d'ensemble

Returns the full postcodes within a range of a full postcode or settlement. Coverage is England. Postcodes accept either case, with or without their space, and return the canonical full spelling.

  • postalCode or settlement is required. When both are supplied, postalCode is used.
  • An ambiguous settlement returns HTTP 400.

ParamètresChaîne de requête

authKeystringObligatoire

Every request needs an API key, which you can get in the portal.

When you call the API from a browser, visitors can see your API key. Limit it to your own domains in the portal, or send the requests through your own server so the key stays hidden.

postalCodestring
Exemple
B1 1BD
Motif
^ *[A-Za-z]{1,2}[0-9][0-9A-Za-z]? *[0-9][A-Za-z]{2} *$
settlementstring

The address's settlement (city, town, village, or hamlet).

Exemple
Birmingham City Centre
searchRangeinteger

The range to search, in meters. Maximum 100000.

Exemple
10000
Par défaut
5000
Min.
1
Max.
100000
maxResultsinteger

The amount of results returned, a number between 1 and 999. Default value is 10.

Par défaut
10
Min.
1
Max.
999
includeInitialPostalCodeboolean

Option whether to include the initial postal code in /v2/range calls. If the value is True, then the initial postal code is included in the search.

Par défaut
false

Réponses

200Postcodes within range, or an empty array when nothing matchesListe de résultats
ChampTypeValeur d'exempleDescription
postalCodestring"B1 2AP"

The complete unit postcode in uppercase, with a space before the inward code.

distanceinteger26

Straight-line distance in metres from the requested postal code or settlement, rounded to whole metres.

latnumber52.4788

Representative latitude of the postal code.

lngnumber-1.90302

Representative longitude of the postal code.

Exemple de réponse
[
  {
    "postalCode": "B1 2AP",
    "distance": 26,
    "lat": 52.4788,
    "lng": -1.90302
  },
  {
    "postalCode": "B1 2AF",
    "distance": 43,
    "lat": 52.4788,
    "lng": -1.9036
  },
  {
    "postalCode": "B1 2AH",
    "distance": 43,
    "lat": 52.4788,
    "lng": -1.9036
  },
  {
    "postalCode": "B1 2AJ",
    "distance": 64,
    "lat": 52.47878,
    "lng": -1.90395
  },
  {
    "postalCode": "B1 2BJ",
    "distance": 91,
    "lat": 52.47879,
    "lng": -1.90438
  },
  {
    "postalCode": "B1 2AZ",
    "distance": 100,
    "lat": 52.47868,
    "lng": -1.90445
  },
  {
    "postalCode": "B1 2BF",
    "distance": 100,
    "lat": 52.47868,
    "lng": -1.90445
  },
  {
    "postalCode": "B1 1BB",
    "distance": 124,
    "lat": 52.48014,
    "lng": -1.90289
  },
  {
    "postalCode": "B1 1BE",
    "distance": 186,
    "lat": 52.4774,
    "lng": -1.90247
  },
  {
    "postalCode": "B1 1FJ",
    "distance": 191,
    "lat": 52.47814,
    "lng": -1.9055
  }
]

Erreurs

Champs d'une réponse d'erreur
ChampTypeDescription
error_idstring

The reason the request failed, such as INVALID_VALUE. The response lists the reasons this operation returns.

errorsarray of object

One entry per problem found in the request.

errors[].messagestring

A readable explanation of the problem, in English.

errors[].helpstring

A link to the documentation section that covers the problem.

errors[].parameterany

The parameter the problem is about. Usually its name; a list when several parameters are involved, or a name with the values to choose from when the request must select one.

errors[].valueany

The value the request sent for parameter, when it has one.

400Requête invalide
MISSING_PARAMETER

Neither postalCode nor settlement is supplied.

MISSING_PARAMETER
{
  "error_id": "MISSING_PARAMETER",
  "errors": [
    {
      "message": "Required parameter postalCode is missing",
      "help": "https://pro6pp.nl/docs/v2/redoc#operation/public_api.v2_generic.range.router.gb",
      "parameter": "postalCode"
    },
    {
      "message": "Required parameter settlement is missing",
      "help": "https://pro6pp.nl/docs/v2/redoc#operation/public_api.v2_generic.range.router.gb",
      "parameter": "settlement"
    }
  ]
}
INVALID_PARAMETER_TYPE

A value has the wrong type, such as a non-integer searchRange.

INVALID_PARAMETER_TYPE
{
  "error_id": "INVALID_PARAMETER_TYPE",
  "errors": [
    {
      "message": "parameter: searchRange has invalid 5km, should be integer",
      "help": "https://pro6pp.nl/docs/v2/redoc#operation/public_api.v2_generic.range.router.gb",
      "parameter": "searchRange"
    }
  ]
}
INVALID_VALUE

A value is malformed or out of bounds, or the postalCode or settlement origin cannot be found.

INVALID_VALUE
{
  "error_id": "INVALID_VALUE",
  "errors": [
    {
      "message": "value is invalid",
      "help": "https://pro6pp.nl/docs/v2/redoc#operation/public_api.v2_generic.range.router.gb",
      "parameter": "postalCode",
      "value": "invalid"
    }
  ]
}
MULTIPLE_RESULTS_FOUND

The settlement is ambiguous.

MULTIPLE_RESULTS_FOUND
{
  "error_id": "MULTIPLE_RESULTS_FOUND",
  "errors": [
    {
      "message": "Multiple results found",
      "help": "https://pro6pp.nl/docs/v2/redoc#operation/public_api.v2_generic.range.router.gb"
    }
  ]
}
401Non autorisé
UNAUTHORIZED

The API key is missing, unknown, revoked or expired, its subscription is not active, the request does not match the key's allowlist, or the subscription does not include this call.

UNAUTHORIZED
{
  "error_id": "UNAUTHORIZED",
  "errors": [
    {
      "message": "No authorization token provided",
      "help": "https://pro6pp.nl/docs/v2/redoc#section/Authentication"
    }
  ]
}

Exemples de code

curl "https://api.pro6pp.nl/v2/range/gb?postalCode=B1+1BD&settlement=Birmingham+City+Centre&searchRange=10000&authKey=YOUR_API_KEY"

Nous vous encourageons à demander un exemple de code dans votre langue préférée.

Pas à pas

Créez un formulaire rapide pour tester la fonctionnalité Grande-Bretagne Range en suivant les étapes ci-dessous.

  1. Créez la page HTML

    Nous commençons par créer une page HTML vide, contenant une structure de page web minimale. Créez un nouveau fichier .html nommé pro6pp_grande-bretagne_range.html. Ajoutez le code suivant entre les balises <body> et </body>. Cela ajoute les champs de saisie pour saisir l'adresse.

    pro6pp_grande-bretagne_range.html
    <form class="form" id="form">
      <div>Call</div>
      <div>
        <label for="postalCode">postalCode:</label>
        <input id="postalCode" class="postalCode" placeholder="B1 1BD"/>
        <label for="settlement">settlement:</label>
        <input id="settlement" class="settlement" placeholder="Birmingham City Centre"/>
        <label for="searchRange">searchRange:</label>
        <input id="searchRange" class="searchRange" placeholder="10000"/>
        <label for="maxResults">maxResults:</label>
        <input id="maxResults" class="maxResults" placeholder=""/>
        <label for="includeInitialPostalCode">includeInitialPostalCode:</label>
        <input id="includeInitialPostalCode" class="includeInitialPostalCode" placeholder=""/>
      </div>
      <div>
        <span style="color: red" class="message"></span>
      </div>
      <div>
        <button type="submit">Submit</button>
      </div>
      <br />
      <div>Response</div>
      <br />
      <div>Full Response</div>
      <pre class="jsonResponse"></pre>
    </form>
  2. Ajoutez une interaction

    Ajoutez le code JavaScript suivant dans un fichier pro6pp_grande-bretagne_range.js séparé. Les ID et les noms de classe des éléments HTML doivent correspondre à ceux spécifiés dans ce fichier JavaScript afin d'obtenir des résultats corrects.

    pro6pp_grande-bretagne_range.js
    document.addEventListener("DOMContentLoaded", function() {
        const pro6ppAuthKey = "AUTH_KEY"; // Replace with your actual authorization key
    
        let messageSpan = document.querySelector(".message");
        let jsonResponseSpan = document.querySelector(".jsonResponse");
        const BASE_URL = "https://api.pro6pp.nl/v2";
    
        function fetchAddress(authKey) {
            const queryParams = {
                authKey: authKey
            };
            const optionalQueryParams = [
                "postalCode",
                "settlement",
                "searchRange",
                "maxResults",
                "includeInitialPostalCode",
            ];
            for (const name of optionalQueryParams) {
                const value = document.getElementById(name).value;
                if (value !== "") {
                    queryParams[name] = value;
                }
            }
    
            let encodedUrl = new URL(`${BASE_URL}/range/gb`);
            encodedUrl.search = new URLSearchParams(queryParams);
    
            fetch(encodedUrl)
                .then(async (response) => {
                    const data = await response.json();
                    if (data) {
                        messageSpan.textContent = "";
                        jsonResponseSpan.textContent = JSON.stringify(data, null, 2);
                    }
                })
                .catch((error) => {
                    console.error("Error fetching: ", error);
                    messageSpan.textContent = error.message;
                });
        }
    
        const form = document.getElementById("form");
        form.onsubmit = function (event) {
            event.preventDefault();
            fetchAddress(pro6ppAuthKey);
        }
    });
  3. Faites-le fonctionner

    Liez le fichier JavaScript à l'intérieur du pro6pp_grande-bretagne_range.html fichier juste avant de fermer la balise </body>.

    pro6pp_grande-bretagne_range.html
      ...
      <script src="pro6pp_grande-bretagne_range.js"></script>
     </body>
    </html>

    Pour accéder au service Web Pro6PP, vous devez demander votre clé d'autorisation personnelle. Cette clé vous est envoyée par e-mail juste après votre inscription. Remplacez l'espace réservé ci-dessus AUTH_KEY par votre clé d'autorisation personnelle.

    Si vous n'avez pas encore de compte, inscrivez-vous pour un essai gratuit de 2 mois. Après avoir créé votre compte, allez dans les détails de votre abonnement et copiez votre AUTH_KEY. Vous aurez besoin de cette clé pour authentifier vos demandes.

  4. Le voir en action

    Une fois que vous avez terminé les étapes précédentes, il est temps de exécuter le formulaire localement dans votre navigateur. Vous devriez maintenant avoir deux fichiers dans le même dossier sur votre ordinateur :

    • pro6pp_grande-bretagne_range.html - la page HTML contenant le formulaire.
    • pro6pp_grande-bretagne_range.js - le fichier JavaScript qui gère l'interaction.

    Vous pouvez maintenant ouvrir le fichier HTML dans votre navigateur en double-cliquant dans votre explorateur de fichiers (par exemple, Finder sous macOS ou Explorateur de fichiers sous Windows). Vous pouvez également l'ouvrir manuellement dans le navigateur en utilisant le chemin complet file:///. Par exemple, vous pouvez ouvrir le fichier en utilisant le chemin complet file:/// :

    Exemples de chemins d'accès aux fichiers
    file:///C:/Users/YourName/Documents/pro6pp_grande-bretagne_range.html
    file:///Users/yourname/Desktop/pro6pp_grande-bretagne_range.html

    Une fois la page ouverte, commencez à saisir les champs du formulaire et cliquez sur Submit pour voir la réponse de l'API s'afficher dans la section « Full Response ».