Skip to content

Action

gbif_record_show(context, data_dict) ΒΆ

Retrieve a GBIF record with the given GBIF ID. This is done via the GBIF API.

Parameters:

Name Type Description Default
context

CKAN context

required
data_dict

dict of parameters, only one is required: gbif_id

required
Source code in ckanext/gbif/logic/action.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def gbif_record_show(context, data_dict):
    """
    Retrieve a GBIF record with the given GBIF ID. This is done via the GBIF API.

    :param context: CKAN context
    :param data_dict: dict of parameters, only one is required: gbif_id
    """
    gbif_id = toolkit.get_or_bust(data_dict, 'gbif_id')
    try:
        response = requests.get(
            f'https://api.gbif.org/v1/occurrence/{gbif_id}', timeout=5
        )
    except requests.Timeout:
        raise toolkit.ObjectNotFound('GBIF request timed out')
    # if there was an error getting the record, raise a not found error
    if 400 <= response.status_code < 600:
        raise toolkit.ObjectNotFound(
            f'GBIF request failed with code {response.status_code}'
        )
    else:
        return response.json()