# Mursketori API — Sample Code

Base URL: `https://mursketori.com/API/v1`  
Full documentation: `https://mursketori.com/API/docs.php`  
Request an API key: info@mursketori.com

---

## Authentication

Every request must include your API key as a Bearer token:

```
Authorization: Bearer mrsk_your_key_here
```

There are two key types:
- **Quarry Owner key** — manage your own quarries and piles (`/quarries.php`, `/piles.php`)
- **Laboratory key** — list assigned quarries (`/quarries.php`, optionally `?ownerid=N`), manage assigned piles, test marks, and PDF documents (`/lab/...`)

---

## Samples

### PHP (`php/`)

| File | Description |
|---|---|
| `list_quarries.php` | List quarries, list piles, create and delete a quarry |
| `list_owners.php` | List quarry owners this API key can access |
| `lab_upload_report.php` | List assigned piles, mark as tested, upload/delete PDF (uses cURL) |

Run from the command line:
```bash
php list_quarries.php
php list_owners.php
php lab_upload_report.php
```

### JavaScript (`js/`)

| File | Description |
|---|---|
| `list_quarries.js` | List quarries the API key can access, optionally by owner (browser or Node 18+) |
| `list_owners.js` | List quarry owners the API key can access (browser or Node 18+) |

```bash
node list_quarries.js
node list_owners.js
```

### Visual Basic 6 (`vb6/`)

| File | Description |
|---|---|
| `MursketoriAPI.bas` | Quarry owner: GET / POST / PUT / DELETE quarries and piles |
| `list_owners.bas` | List quarry owners the API key can access |
| `MursketoriLabAPI.bas` | Laboratory: list quarries (optionally by owner), piles, mark tested, upload/delete PDFs |

**Setup:**
1. Open your VB6 project.
2. Add the `.bas` module: **Project → Add Module → Existing**.
3. Add references: **Project → References**
   - `Microsoft WinHTTP Services, version 5.1` (winhttp.dll)
   - `Microsoft XML, v6.0` (msxml6.dll) — required for file upload only
4. Set `API_KEY` / `LAB_API_KEY` constant at the top of the module.
5. Call the `Example*` functions from your form or startup code.

**Note on JSON parsing:** VB6 has no built-in JSON parser. The samples use a minimal
`JsonValue()` helper for simple fields. For production code with array/nested responses,
add a JSON library such as [VB-JSON](https://github.com/cjson/VB-JSON) or mdJSON.

---

## Quick reference

```
GET    /API/v1/owners.php              List accessible quarry owners

GET    /API/v1/quarries.php              List quarries (owner key: own; lab key: all assigned)
GET    /API/v1/quarries.php?ownerid=N    List quarries of a specific owner
GET    /API/v1/quarries.php?id=N         Get one quarry
POST   /API/v1/quarries.php              Create quarry
PUT    /API/v1/quarries.php?id=N         Update quarry
DELETE /API/v1/quarries.php?id=N         Delete quarry

GET    /API/v1/piles.php?quarry_id=N     List piles in a quarry
GET    /API/v1/piles.php?id=N            Get one pile
POST   /API/v1/piles.php                 Create pile
PUT    /API/v1/piles.php?id=N            Update pile
DELETE /API/v1/piles.php?id=N            Delete pile

GET    /API/v1/lab/piles.php             List assigned piles (lab key)
POST   /API/v1/lab/mark_tested.php       Mark pile as KL-tested (lab key)
POST   /API/v1/lab/documents.php         Upload PDF report/certificate (lab key, costs 1 credit)
DELETE /API/v1/lab/documents.php         Delete PDF (lab key)
```
