|
2 | 2 |
|
3 | 3 | [metadata visualizations](https://metadata-portal.allenneuraldynamics.org/) |
4 | 4 |
|
5 | | -## Validation endpoints |
| 5 | +## REST API |
| 6 | + |
| 7 | +The portal exposes a REST API served by FastAPI/uvicorn. |
| 8 | + |
| 9 | +### Gather endpoint |
| 10 | + |
| 11 | +Gathers and validates metadata from the metadata service for a given subject. |
| 12 | + |
| 13 | +- `POST /gather` — body is a JSON object with required `subject_id` and `project_name` |
| 14 | +- Optional body keys: `metadata_service_url`, `modalities` (list), `tags` (list), `group`, `restrictions`, `data_summary`, `acquisition_start_time` |
| 15 | + |
| 16 | +```python |
| 17 | +response = requests.post( |
| 18 | + "https://metadata-portal.allenneuraldynamics-test.org/gather", |
| 19 | + json={"subject_id": "123456", "project_name": "MyProject"}, |
| 20 | +) |
| 21 | +print(response.json()) |
| 22 | +``` |
| 23 | + |
| 24 | +### Upgrade endpoint |
| 25 | + |
| 26 | +`POST /upgrade` accepts a `metadata.json` dict and runs it through [`aind-metadata-upgrader`](https://github.com/AllenNeuralDynamics/aind-metadata-upgrader). It always returns original and upgraded JSON side by side for each field, even when some fields fail. |
| 27 | + |
| 28 | +```python |
| 29 | +import requests, json |
| 30 | + |
| 31 | +with open("metadata.json") as f: |
| 32 | + metadata = json.load(f) |
| 33 | + |
| 34 | +response = requests.post( |
| 35 | + "https://metadata-portal.allenneuraldynamics.org/upgrade", |
| 36 | + json=metadata, |
| 37 | +) |
| 38 | +result = response.json() |
| 39 | +# result["overall_success"] — True if all fields upgraded cleanly |
| 40 | +# result["overall_error"] — error string if the full upgrade failed |
| 41 | +# result["partial_success"] — True if at least one field succeeded |
| 42 | +# result["files_tested"] — per-field breakdown |
| 43 | +``` |
| 44 | + |
| 45 | +### Query endpoints |
| 46 | + |
| 47 | +- `GET /upgrade-query` — Build a query using the LLM query builder. |
| 48 | +- `POST /retrieve-records` — Run a query against the metadata store. |
| 49 | + |
| 50 | +Optional query parameters for `/retrieve-records`: |
| 51 | +- `names_only=true` — return only asset names |
| 52 | +- `limit=<int>` — limit number of results (default 0 = no limit) |
| 53 | +- `projection=<json>` — JSON object specifying which fields to include/exclude |
| 54 | + |
| 55 | +```python |
| 56 | +response = requests.post( |
| 57 | + "https://metadata-portal.allenneuraldynamics-test.org/retrieve-records", |
| 58 | + params={"limit": 10, "projection": '{"subject.subject_id": 1, "name": 1}'}, |
| 59 | + json={"subject.subject_id": "123456"}, |
| 60 | +) |
| 61 | +print(response.json()) |
| 62 | +``` |
| 63 | + |
| 64 | +### Contributions endpoints |
| 65 | + |
| 66 | +Stores and retrieves [CRediT](https://credit.niso.org/) authorship contributions for a project, versioned via SQLite. |
| 67 | + |
| 68 | +| Endpoint | Description | |
| 69 | +|---|---| |
| 70 | +| `GET /contributions/get?project=<name>` | Latest contribution data (JSON by default) | |
| 71 | +| `GET /contributions/get?project=<name>&format=yaml` | Latest contribution data as YAML | |
| 72 | +| `GET /contributions/get?project=<name>&commit=<hash>` | Contribution data at a specific commit | |
| 73 | +| `GET /contributions/get?project=<name>&history=true` | List of all commits, newest first | |
| 74 | +| `GET /contributions/get?doi=<doi>` | Look up a project by DOI | |
| 75 | +| `POST /contributions/post?project=<name>[&message=<msg>][&password=<hash>]` | Store a new version; body is JSON or YAML | |
| 76 | +| `GET /contributions/token?doi=<doi>&type=add_author\|edit_author[&author=<name>][&days=<n>][&password=<hash>]` | Create a scoped token for a project | |
| 77 | +| `GET /contributions/author-image?author=<name>` | Returns the S3 key for an author's headshot | |
| 78 | + |
| 79 | +## Local dev |
| 80 | + |
| 81 | +```sh |
| 82 | +uv sync --extra dev |
| 83 | +uvicorn aind_metadata_viz.main:app --reload |
| 84 | +``` |
| 85 | + |
| 86 | +## CI/CD |
| 87 | + |
| 88 | +```sh |
| 89 | +docker build -t aind-metadata-viz . |
| 90 | +docker run -p 8000:8000 aind-metadata-viz |
| 91 | +``` |
6 | 92 |
|
7 | 93 | The metadata portal hosts validation endpoints for the latest [`aind-data-schema`](https://github.com/AllenNeuralDynamics/aind-data-schema) release. You can hit these endpoints with: |
8 | 94 |
|
|
0 commit comments