General information

What is it about?

An API, short for Application Programming Interface, is a set of services that can be called from a computer program (“Machine to Machine” interface). It's a computer interface, as opposed to a (human) graphical user interface. Technically the Agri-food Data API is a Web API, consisting of a set of addresses (URLs) that may be used to retrieve information from the portal's database. The information is substantially the same as what you can see in the "Data Explorer" tab of the corresponding portal app, but the format is suitable for consumption by computers rather than human beings – even though humans can still read it! It is formatted in a structure known as JSON.

Here is an example of a query URL to retrieve some Portuguese beef prices from 2019 and 2020:


The key=value pairs after the question mark are filtering parameters to limit the reply to only those records that you need. If you click on that link you will see a typical JSON-formatted reply with curly braces {} to separate records. You can also experiment by varying the parameter values in the address bar of your browser. The general structure of a request is:

url_api

Where host_URL is the fixed address of our API server, service is the name of the particular web service, and filters is a series of parameter-based restrictions separated by & signs. The available filter parameters depend on the service, as described in later sections of this document.

Using your favourite spreadsheet application

A relatively simple way of putting the API to work is by launching the query from inside a spreadsheet application. Consult the documentation of your favourite spreadsheet tool and look for something like “getting data from the Web”. Where it says "address" or "URL", paste the above URL. In some spreadsheet applications this may require writing a macro.

CORS policy: protection against cross-scripting attacks

Https responses from ec.europa.eu or its subdomains do not enable CORS scripting.

If you try to make our data available to users within your organisation by developing an internal web application of your own, please be aware that modern browsers will block third-party responses (where the Agri-food data portal API is the third party in this case) by default.

As a web developer, you may circumvent this limitation by offering our data through a proxy service under the same hostname and port number as your web application. From the perspective of the browser, the web application and the data will then appear to come from a single web server.

As an end user, you can configure your browser to disable protection against cross-scripting, but obviously this comes with the risk of exposure to such attacks.