Getting started overview

This guide provides a structured approach to programmatically accessing the Open Government, Cyprus data portal. The portal, established in 2012, serves as the central hub for public sector information in Cyprus, supporting government transparency and facilitating data-driven initiatives. Unlike many commercial APIs, the Open Government, Cyprus portal makes all its data freely available without a tiered pricing structure, making it a valuable resource for developers, researchers, and public sector applications.

The core of programmatic interaction with the Open Government, Cyprus portal is through its CKAN-based API. CKAN, an open-source data portal platform, provides a standardized way to access datasets, including functionalities for searching, retrieving metadata, and downloading data files. Understanding the CKAN API structure is key to efficient data retrieval from the Cyprus Open Data Portal.

Before making your first API request, you will register for an account on the Open Government, Cyprus portal. This account grants you access to generate an API key, which is essential for authenticating your requests and ensuring proper usage tracking, even for free data access. This guide will walk you through the account creation process, the retrieval of your API key, and the construction of a basic API call to verify your setup.

Quick Start Table

Step What to Do Where
1. Register Create an account on the Open Data Portal. Cyprus Open Data Portal registration
2. Get API Key Generate your personal API key from your profile settings. Your user profile on data.gov.cy
3. Make Request Formulate and execute your first API call to a specific CKAN endpoint. Using a tool like curl or a programming language's HTTP client
4. Explore Data Browse available datasets and their documentation. Cyprus Open Data Portal datasets

Create an account and get keys

Accessing the Open Government, Cyprus API requires an API key for authentication, even though all data is freely available. This key helps the portal manage usage and provides a layer of accountability for data access. The process involves registering on the main data portal and then generating an API key from your user profile.

Account Registration

  1. Navigate to the Portal: Open your web browser and go to the official Cyprus Open Data Portal homepage.
  2. Locate Registration: Look for a "Register" or "Sign Up" link, typically found in the header or footer of the website.
  3. Complete Form: Fill out the registration form with your desired username, email address, and a strong password. You may also need to provide your full name and agree to terms of service. Ensure your email address is active, as you will likely need to verify it.
  4. Verify Email: Check your inbox for a verification email from the Open Government, Cyprus portal. Click the link within the email to activate your account. If you don't receive it, check your spam or junk folders.
  5. Log In: Once your email is verified, return to the portal and log in with your newly created credentials.

API Key Generation

After successfully logging into your account, you can generate your API key:

  1. Access Profile: Click on your username, usually in the top right corner of the portal, to access your user profile or dashboard.
  2. Find API Key Section: Within your profile settings, look for a section related to "API Key" or "Developer Settings." This section typically contains an option to view or generate your API key.
  3. Generate Key: If a key is not already present, there will be a button or link to "Generate API Key" or "New API Key." Click this to create your unique identifier.
  4. Copy Key: Once generated, your API key will be displayed. Copy this key immediately and store it securely. It is treated like a password; anyone with your key can make requests on your behalf. The portal may only show the key once, or provide an option to regenerate it, invalidating the old one.

For more detailed instructions on managing your account and API keys, consult the Cyprus Open Data Portal API documentation.

Your first request

With an active account and your API key in hand, you're ready to make your first programmatic call to the Open Government, Cyprus API. The API is built on CKAN, which uses a RESTful architecture. We will use the package_list endpoint to retrieve a list of all available datasets (packages) as a starting point. This request requires only your API key for authentication.

The CKAN API documentation outlines various endpoints for interacting with data. The package_list endpoint is commonly used for discovering available datasets.

Using cURL (command line)

curl is a widely available command-line tool for making HTTP requests. It's an excellent way to test API calls quickly without writing code.

curl -X GET \ 
  -H "Authorization: YOUR_API_KEY" \ 
  "https://www.data.gov.cy/api/3/action/package_list"

Replace YOUR_API_KEY with the actual API key you obtained from your Open Government, Cyprus profile. This command sends a GET request to the package_list endpoint, including your API key in the Authorization header.

A successful response will return a JSON array containing the names (IDs) of all datasets hosted on the portal. For example:

{
  "help": "https://www.data.gov.cy/api/3/action/help_show?name=package_list",
  "success": true,
  "result": [
    "dataset-name-1",
    "dataset-name-2",
    // ... more dataset names
  ]
}

Using Python

For a programmatic approach, Python with the requests library is a common choice:

import requests
import json

api_key = "YOUR_API_KEY" # Replace with your actual API key
base_url = "https://www.data.gov.cy/api/3/action/"
endpoint = "package_list"

headers = {
    "Authorization": api_key
}

response = requests.get(f"{base_url}{endpoint}", headers=headers)

if response.status_code == 200:
    data = response.json()
    print("Successfully retrieved package list:")
    print(json.dumps(data["result"][:5], indent=2)) # Print first 5 dataset names
else:
    print(f"Error: {response.status_code}")
    print(response.text)

Remember to install the requests library if you haven't already: pip install requests. This Python script performs the same GET request as the curl example, demonstrating how to handle headers and parse the JSON response programmatically.

Common next steps

After successfully making your first API call to the Open Government, Cyprus portal, several common next steps can help you further integrate and utilize the available data:

  1. Explore Datasets: Use the package_list output to identify specific datasets of interest. You can then use the package_show endpoint to retrieve detailed metadata for a particular dataset, including its resources (files), descriptions, and tags. This will help you understand the content and structure of each dataset. Refer to the Cyprus Open Data Portal API Reference for details on dataset exploration endpoints.
  2. Access Data Resources: Many datasets contain links to actual data files (e.g., CSV, JSON, XML). Once you have the resource ID or URL from package_show, you can directly download these files. Some resources might also be accessible through the CKAN DataStore API if the data is stored in the portal's integrated DataStore, allowing for more advanced querying directly through the API.
  3. Implement Search Functionality: The CKAN API provides powerful search capabilities. The package_search endpoint allows you to search for datasets based on keywords, tags, groups, or other metadata fields. This is crucial for applications that need to dynamically discover relevant data.
  4. Handle Pagination: For endpoints that return large lists (like package_list or package_search), the API typically implements pagination to limit the number of results per request. Understand how to use the offset and limit (or similar) parameters to retrieve all results incrementally.
  5. Error Handling and Rate Limits: Implement robust error handling in your applications to gracefully manage API errors (e.g., invalid requests, server errors). While the Open Government, Cyprus portal does not explicitly publish strict rate limits, it's good practice to design your application to avoid overwhelming the server with excessive requests. Using exponential backoff for retries can be a good strategy, as described in guides like the Google Cloud retry strategy documentation.
  6. Stay Informed: Periodically check the Cyprus Open Data Portal for announcements regarding new datasets, API updates, or changes in policies.

Troubleshooting the first call

Encountering issues during your first API call is common. Here's a guide to diagnose and resolve typical problems:

  1. Invalid API Key (HTTP 403 Forbidden):
    • Symptom: The API returns an HTTP 403 Forbidden status code, often with a message indicating "Unauthorized" or "Invalid API key."
    • Solution: Double-check that you've correctly copied and pasted your API key. Ensure there are no leading or trailing spaces. Verify that the key is included in the Authorization header exactly as shown in the examples (Authorization: YOUR_API_KEY). If in doubt, generate a new API key from your profile on the Cyprus Open Data Portal and retry.
  2. Incorrect Endpoint or URL (HTTP 404 Not Found):
    • Symptom: The API returns an HTTP 404 Not Found status code.
    • Solution: Verify the URL you are calling. Ensure the base URL (https://www.data.gov.cy/api/3/action/) and the endpoint name (package_list) are spelled correctly and match the official API documentation. Typos in the URL are frequent causes of 404 errors.
  3. Network Issues (Connection Timed Out, DNS Error):
    • Symptom: Your request fails with a network-related error message (e.g., "Connection refused," "Name or service not known," "Timed out").
    • Solution: Check your internet connection. Ensure there are no firewall rules or proxy settings on your local machine or network that might be blocking outbound API calls. Try accessing the Open Data Portal homepage directly in your browser to confirm connectivity to the server.
  4. Server-Side Errors (HTTP 5xx Status Codes):
    • Symptom: The API returns an HTTP 500 Internal Server Error, 502 Bad Gateway, or similar 5xx status codes.
    • Solution: These errors indicate a problem on the server side, not with your request. This could be temporary maintenance or an unexpected issue. Wait a few minutes and try your request again. If the problem persists, check the Open Government, Cyprus portal for any announcements or service status updates.
  5. Unexpected JSON Response or Parsing Errors:
    • Symptom: The API call succeeds (HTTP 200 OK), but the returned data is not in the expected JSON format, or your application fails to parse it.
    • Solution: Inspect the raw response text. Sometimes, an API might return an HTML error page or a different format if an underlying issue occurred. Ensure your programming language's HTTP client is correctly configured to expect and parse JSON. Confirm that the endpoint you are calling is indeed supposed to return JSON.
  6. Using HTTP instead of HTTPS:
    • Symptom: Connection errors or redirects.
    • Solution: Always use HTTPS (https://www.data.gov.cy/) for API calls to ensure secure communication. Most modern APIs enforce HTTPS, and using HTTP might result in connection failures or security warnings, as highlighted by resources on web security best practices.

Always consult the Open Government, Cyprus API documentation for the most accurate and up-to-date information regarding endpoints, parameters, and error codes.