# XNAT Imaging Extractor (`datamule/xnat-imaging-extractor`) Actor

Point at ANY public XNAT neuroimaging server (NITRC-IR, BMIA, institutional archives) and pull structured metadata over the XNAT REST API: projects, subjects, imaging experiments/sessions, and scans. One actor, the whole /data REST surface, every row lossless.

- **URL**: https://apify.com/datamule/xnat-imaging-extractor.md
- **Developed by:** [Datamule](https://apify.com/datamule) (community)
- **Categories:** Developer tools, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.35 / 1,000 records

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## XNAT Imaging Extractor

Point at **any public [XNAT](https://www.xnat.org/) server** and pull structured
neuroimaging metadata over the standard [XNAT REST API](https://wiki.xnat.org/xnat-api).
XNAT is the de-facto open-source platform for neuroimaging & clinical imaging research
data management, and every install — the [NITRC image repository](https://www.nitrc.org/ir),
the [BMIA public archive](https://xnat.bmia.nl), `central.xnat.org`, and countless
institutional deployments — speaks the **identical** `/data/...` REST surface. So there
is no per-server scraper: give a base URL and a mode, get clean rows.

### Modes

| `mode`        | Returns                                   | Endpoint |
|---------------|-------------------------------------------|----------|
| `projects`    | one row per project (whole server)        | `/data/projects` |
| `subjects`    | one row per subject in a project          | `/data/projects/{projectId}/subjects` |
| `experiments` | one row per imaging session in a project  | `/data/projects/{projectId}/experiments` |
| `scans`       | one row per scan in a session             | `/data/experiments/{experimentId}/scans` |

- `subjects` and `experiments` need a **`projectId`**.
- In `experiments` mode, add a **`subjectId`** to narrow to one subject.
- `scans` needs an **`experimentId`**.

### Input

```json
{
  "serverUrl": "https://www.nitrc.org/ir",
  "mode": "projects",
  "maxRecords": 1000
}
```

Drill down further:

```json
{ "serverUrl": "https://www.nitrc.org/ir", "mode": "subjects",    "projectId": "ixi" }
{ "serverUrl": "https://www.nitrc.org/ir", "mode": "experiments", "projectId": "studyforrest_rev003" }
{ "serverUrl": "https://www.nitrc.org/ir", "mode": "scans",       "experimentId": "NITRC_IR_E07478" }
```

| Field | Type | Notes |
|-------|------|-------|
| `serverUrl` | string (required) | XNAT base URL. **Include any path prefix** — NITRC serves under `/ir`. |
| `mode` | enum | `projects` | `subjects` | `experiments` | `scans` (default `projects`). |
| `projectId` | string | Required for `subjects` / `experiments`. |
| `subjectId` | string | Optional drill-down in `experiments` mode. |
| `experimentId` | string | Required for `scans`. |
| `maxRecords` | integer | Row cap (default 1000). |
| `bearer` | string (secret) | Optional bearer token for authenticated servers. |
| `extraHeaders` | object | Optional extra HTTP headers (e.g. a session cookie). |

### Output

Each row carries the mapped, human-friendly fields for its mode (id, name, label,
project, date, scan type, series description, …) **plus a lossless `_raw`** object with
the complete original API record, so nothing is dropped even when a column key differs
between XNAT versions.

```json
{
  "id": "NITRC_IR_E07478",
  "label": "sub001",
  "project": "studyforrest_rev003",
  "date": "",
  "xsiType": "xnat:mrSessionData",
  "subjectId": "NITRC_IR_E07478",
  "uri": "/data/experiments/NITRC_IR_E07478",
  "_server": "https://www.nitrc.org/ir",
  "_mode": "experiments",
  "_raw": { "...": "complete original record" }
}
```

### Notes on public vs gated servers

`?format=json` is a *request*, not a guarantee. Some XNAT servers gate public browse
behind an interactive login and answer with an **HTML login page at HTTP 200** (e.g.
`central.xnat.org`, `cnda.wustl.edu`). This actor detects that (non-JSON body / no
`ResultSet` envelope) and **fails fast** rather than emitting an empty dataset — it
never fabricates rows and never reports a gated server as an honest zero. Servers that
expose anonymous public projects (NITRC-IR, BMIA) return real JSON and work out of the
box.

### Pricing

Pay-per-event: **$0.0005 per record** (one project / subject / experiment / scan row).
You only pay for rows actually extracted.

# Actor input Schema

## `serverUrl` (type: `string`):

Base URL of a public XNAT server. Include any path prefix the server uses (NITRC serves under '/ir'). Examples: https://www.nitrc.org/ir , https://xnat.bmia.nl . Note: servers that gate public browse behind a login (e.g. central.xnat.org) return an HTML login page and the run will fail fast rather than emit empty.

## `mode` (type: `string`):

What to extract. 'projects' lists all projects on the server. 'subjects' lists subjects in one project (needs projectId). 'experiments' lists imaging sessions in a project (needs projectId; narrow to one subject with subjectId). 'scans' lists scans in one session (needs experimentId).

## `projectId` (type: `string`):

Project ID (the project's 'ID', e.g. 'ixi' on NITRC-IR). Required for 'subjects' and 'experiments' modes.

## `subjectId` (type: `string`):

Optional. In 'experiments' mode, narrow results to a single subject (the subject's 'ID', e.g. 'NITRC\_IR\_S05409').

## `experimentId` (type: `string`):

Experiment / imaging-session ID (e.g. 'NITRC\_IR\_E07478'). Required for 'scans' mode.

## `maxRecords` (type: `integer`):

Maximum number of rows to extract. Leave at the default to cap large listings.

## `bearer` (type: `string`):

Optional bearer token for XNAT servers that expose an authenticated REST API. Leave empty for public servers. Stored securely.

## `userAgent` (type: `string`):

Override the default User-Agent header sent to the server.

## `extraHeaders` (type: `object`):

Optional additional HTTP headers to send with every request (e.g. a cookie for a session-authenticated server).

## `timeoutSecs` (type: `integer`):

Per-request timeout in seconds.

## Actor input object example

```json
{
  "serverUrl": "https://www.nitrc.org/ir",
  "mode": "projects",
  "maxRecords": 1000,
  "timeoutSecs": 120
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "serverUrl": "https://www.nitrc.org/ir"
};

// Run the Actor and wait for it to finish
const run = await client.actor("datamule/xnat-imaging-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "serverUrl": "https://www.nitrc.org/ir" }

# Run the Actor and wait for it to finish
run = client.actor("datamule/xnat-imaging-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "serverUrl": "https://www.nitrc.org/ir"
}' |
apify call datamule/xnat-imaging-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=datamule/xnat-imaging-extractor",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/e8OHc4kWI9zAbyOgm/builds/ywUMfsS4qEfBeaygI/openapi.json
