mirror of
https://github.com/geoadmin/geocat-api-test.git
synced 2026-08-25 21:24:16 +00:00
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.
- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .gitignore | ||
| 1_get_token.py | ||
| 2_search.py | ||
| 3_get_xml_records.py | ||
| 4_get_mef_records.py | ||
| 5_edit_records.py | ||
| 6_upload_record.py | ||
| example.xml | ||
| example.zip | ||
| README.md | ||
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/_searchendpoint.
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/xmlendpoint.
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/zipendpoint.
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/batcheditingendpoints.
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
/recordsendpoint for file uploads.
Setup
- Install dependencies:
pip install requests - Create a
config.pyfile 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.