This page describe this website's free and open RESTful API's behavior

In order to be able to execute write operations, you first need to authenticate and obtain an API Key in your profile settings.

This key should be provided on each call in the X-API-KEY HTTP header.

API calls are subject to the same permissions than the web interface.

By example, you need to be part of the organization to modify one of its datasets.

Some method are paginated and always follow the same pattern. The object list is wrapped in a Page object.

You don't have to compute yourself the previous and next pages because the URLs are available in the response under the previous_page and next_page attributes. They will be set to null if there is no previous and/or next page.

Example:

{
    "data": [{...}, {...}],
    "page": 1,
    "page_size": 20,
    "total": 43,
    "next_page": "http://www.data.gouv.fr/api/endpoint/?page=2",
    "previous_page": null
}

All examples use the httpie and jq utilities for readability purpose. You don't need to use these tools in your code though, they're just helpers to better understand the API.

Verifying that httpie is working

Once httpie is installed, you can verify that it works as expected by typing that command in your shell:

$ http https://www.data.gouv.fr/api/1/organizations/?page_size=1

It should return something in this vein:


HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
... LOTS OF HEADERS ...

{
    "data": [
        {

            ... LOTS OF DATA ...

            "name": "Premier ministre",
            "page": "https://www.data.gouv.fr/fr/organizations/premier-ministre/",
            "slug": "premier-ministre",
            "uri": "https://www.data.gouv.fr/api/1/organizations/premier-ministre/",
            "url": null
        }
    ],
    "next_page": "https://www.data.gouv.fr/api/1/organizations/?page=2&page_size=1",
    "page": 1,
    "page_size": 1,
    "previous_page": null,
    "total": 529
}

This is very verbose and we don't need all that information yet. That's why we use jq.

Verifying that jq is working

Once jq is installed, you can verify that it works as expected by typing that command in your shell:

$ http https://www.data.gouv.fr/api/1/organizations/?page_size=1 | jq '.data[].name'

It should return something in this vein:

"Premier ministre"

That's definitely better! Now that we're sure that it works as expected, let's shorten a bit the command line:

$ export API="https://www.data.gouv.fr/api/1/"

The previous command is now equivalent to the more readable (don't forget the quotes):

$ http $API'organizations/?page_size=1' | jq '.data[].name'

That's a good start, now let's dig into the API itself. We don't know it yet but we already fetched our first organization.

Browsing and retrieving data

You can retrieve a list of organization (filtered or not) or a unique organization. When you reach an endpoint, the default page size is 20. Let's fetch the first 20 organization from the API:

$ http $API'organizations/' | jq '.data[].name'

"Premier ministre"
"Eurostat"
"Institut National de la Statistique et des Etudes Economiques (INSEE)"
"Ministère de l'Intérieur"
"Ministère des finances et des comptes publics"
"Ministère de la Culture et de la Communication"
"Education Nationale"
"Institut National de l'Information Géographique et Forestière"
"Ministère des Affaires sociales, de la Santé et des Droits des femmes"
"Région Île-de-France"
"Enseignement supérieur et Recherche"
"Caisse nationale de l'assurance maladie des travailleurs salariés"
"Mairie de Paris"
"La Poste"
"Etalab"
"Ministère de l'Ecologie du Développement Durable et de l'Energie"
"Ministère de l'Agriculture, de l'Agroalimentaire et de la Forêt"
"Ministère des Affaires Etrangères et du Développement International (MAEDI)"
"Ministère de la ville, de la jeunesse et des sports"
"Ministère du travail, de l'emploi et du dialogue social"

That list is great to have but what if we want to walk through returned organizations? Let's fetch the first 5 organizations URIs:

$ http $API'organizations/?page_size=5' | jq '.data[].uri'

"https://www.data.gouv.fr/api/1/organizations/premier-ministre/"
"https://www.data.gouv.fr/api/1/organizations/eurostat/"
"https://www.data.gouv.fr/api/1/organizations/institut-national-de-la-statistique-et-des-etudes-economiques-insee/"
"https://www.data.gouv.fr/api/1/organizations/ministere-de-l-interieur/"
"https://www.data.gouv.fr/api/1/organizations/ministere-des-finances-et-des-comptes-publics/"

Now we'll be able to retrieve a unique organization thanks to the returned URI:

$ http $API'organizations/premier-ministre/' | jq '.'

That's a lot of data to compute. Let's refine these data, if we want only metrics:

$ http $API'organizations/premier-ministre/' | jq '.metrics'

{
  "dataset_views": 16345,
  "datasets": 178,
  "followers": 79,
  "members": 16,
  "nb_hits": 0,
  "nb_uniq_visitors": 0,
  "nb_visits": 0,
  "permitted_reuses": 82,
  "resource_downloads": 4316,
  "reuse_views": 257,
  "reuses": 3,
  "views": 699
}

Or maybe just the name of the members of that organization:

$ http $API'organizations/premier-ministre/' | jq '.members[].user.last_name'

"Javelle"
"Pelletier"
"des victimes de spoliations"
"Mestre"
"BENVENUTO"
""
"Tales"
"Saint-Aubin "
"Biafora"
"Cottin"
"ROGER"
"des retraites (Premier ministre)"
"Modestine"
"Roullier"
"Roullier"
"Chignard"

It's really up-to-you to retrieve the data that matters to your project. Do not hesitate to go through the jq's tutorial and manual if you want to browse the API through the command-line in depth.

Modifying and deleting data

Warning, you're entering a danger zone. Data modifications or deletions with the API are definitive and we don't provide any sandbox to test those prior executing (for now). Be aware of these responsibilities prior to use your great powers.

If you try to modify a resource without an authentication token, a 401 will be returned:

$ http PUT $API'organizations/premier-ministre/'

HTTP/1.1 401 UNAUTHORIZED
... LOTS OF HEADERS ...

{
    "message": "Unauthorized",
    "status": 401
}

You need to specify your API Key (see above) and use the X-API-KEY HTTP header. If you try to modify a resource that you're not in control of, a 400 will be returned instead:

$ http PUT $API'organizations/premier-ministre/' X-API-KEY:your.api.key.here

HTTP/1.1 401 UNAUTHORIZED
... LOTS OF HEADERS ...

{
    "message": "Invalid API Key",
    "status": 401
}

This is the message you will end up with if you specified the wrong API Key. There is another potential error message that you can encounter:


HTTP/1.1 403 FORBIDDEN
... LOTS OF HEADERS ...

{
    "message": "You do not have the permission to modify that object.",
    "status": 403
}

It occurs if you try to access a resource that you cannot edit with your credentials. If your Key is valid you should have something like this:


HTTP/1.1 200 OK
... LOTS OF HEADERS ...

{
    ...
}

But it didn't change anything! This is perfectly normal, we forgot to specify the right data to send to the server.

$ http PUT $API'organizations/premier-ministre/' X-API-KEY:your.api.key.here name="Premier ministre fr" description="Administration du Premier ministre." | jq '{name: .name, description: .description}'

{
  "name": "Premier ministre fr",
  "description": "Administration du Premier ministre."
}

The resource has been modified with your new values. Finally, you can delete a resource with the appropriated HTTP verb (beware, no rollback is possible using the API at the moment):

$ http DELETE $API'organizations/premier-ministre/' X-API-KEY:your.api.key.here

HTTP/1.0 204 NO CONTENT
... LOTS OF HEADERS ...

Once you did it, you can verify that it's effective issuing a GET against the previous URI:

$ http GET $API'organizations/premier-ministre/'

HTTP/1.0 410 GONE
... LOTS OF HEADERS ...

{
    "message": "Organization has been deleted",
    "status": 410
}

Please consult the reference documentation below for further interactions with the API or ask us for questions related to it!