Request examples with the Geonetwork API | Read-only mirror of https://github.com/geoadmin/geocat-api-test — Bundesamt für Landestopografie swisstopo. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-05-26 11:12:04 +02:00
.gitignore first commit 2025-04-15 15:52:05 +02:00
1_get_token.py french to english 2025-04-22 16:04:49 +02:00
2_search.py first commit 2025-04-15 15:52:05 +02:00
3_get_xml_records.py english version 2025-04-28 17:23:07 +02:00
4_get_mef_records.py english version 2025-04-28 17:23:07 +02:00
5_edit_records.py first commit 2025-04-15 15:52:05 +02:00
6_upload_record.py Update 6_upload_record.py 2025-05-26 11:12:04 +02:00
example.xml first commit 2025-04-15 15:52:05 +02:00
example.zip Update MEF upload script to use ZIP file and improve error handling 2025-04-15 16:47:59 +02:00
README.md Update README.md 2025-05-26 11:10:25 +02:00

geocat API Usage Examples

This repository demonstrates 6 different ways to interact with the geocat API using Python scripts.

1. Authentication (1_get_token.py)

  • Logs in to geocat using credentials from config.py.
  • Retrieves and prints the XSRF token.
  • Shows how to authenticate and make authorized requests.

2. Search Records (2_search.py)

  • Performs a metadata search using a JSON query.
  • Prints out the UUID and title of each found record.
  • Demonstrates how to use the /search/records/_search endpoint.

3. Download XML Record (3_get_xml_records.py)

  • Downloads a metadata record as XML using its UUID.
  • Saves or prints the XML content.
  • Uses the /records/{uuid}/formatters/xml endpoint.

4. Download MEF Record (4_get_mef_records.py)

  • Downloads a metadata record as a MEF (Metadata Exchange Format) ZIP file.
  • Saves the MEF file locally.
  • Uses the /records/{uuid}/formatters/zip endpoint.

5. Batch Edit Records (5_edit_records.py)

  • Demonstrates how to batch edit metadata records.
  • Prepares a payload to update or delete metadata fields using XPath.
  • Previews and applies changes using the /records/batchediting endpoints.

6. Upload Record (6_upload_record.py)

  • Uploads a new metadata record as XML or MEF.
  • Shows how to set parameters for publishing and validation.
  • Uses the /records endpoint for file uploads.

Setup

  1. Install dependencies:
    pip install requests
    
  2. Create a config.py file with your credentials:
    GEOCAT_USERNAME = "your_username"
    GEOCAT_PASSWORD = "your_password"
    

Usage

Run any script with:

python <script_name.py>

For example, to upload a record:

python 6_upload_record.py

See each script for more details and endpoint references.