---
name: zalega
description: Manage items, photos and sale listings in the Zalega decluttering app (zalega.puniserv.pl) through its API. Use when the user asks to add, find, update, photograph, list for sale, or mark as sold, given away or discarded things in Zalega.
---

# Zalega API

Base URL: `https://zalega.puniserv.pl`. Every request: `Authorization: Bearer $ZALEGA_TOKEN`
(a personal token from the account screen; if the variable is missing, ask the user to create one there).
Full reference: `https://zalega.puniserv.pl/openapi.yaml`. Fetch it when you need a field this file does not list.

JSON bodies, `Content-Type: application/json`. Ids are UUIDs. Prices are decimal strings with two places
(`"120.00"`, `"0.00"` = free); you may send a number. In PATCH only the keys you send change; `null` clears an optional
field (items: `description`, `category`, `condition`, `target_price`, `notes`; listings: `title`, `description`, `url`,
`notes`, `price_listed`).

## Start

1. `GET /api/spaces`: the user's spaces (storage places). Pick one by name, or ask. Every other call is under `/api/spaces/{space}`.
2. `GET /api/spaces/{space}/categories`: categories already in use. Reuse them instead of inventing near-duplicates.
3. `GET /api/platforms`: selling platforms (`key`, `name`, advisory `max_title` / `max_description`).

## Items

- Find: `GET /api/spaces/{space}/items`, optional `?status=stored|ready|listed|sold|given_away|discarded`
  (`listed` = a stored or ready item with a published listing; such items do not match `stored` or `ready`). Returns summaries; filter by `name` / `category` yourself.
- Details with photos and listings: `GET /api/spaces/{space}/items/{id}`.
- Add: `POST /api/spaces/{space}/items` with `{"name": "Desk lamp"}` (only `name` is required) → 201 with `id`.
  Optional fields: `description`, `category`, `condition` (`new`, `like_new`, `good`, `used`, `damaged`),
  `target_price`, `notes` (private), `is_public` (show on the space's public page), `status`.
- Edit or change status: `PATCH /api/spaces/{space}/items/{id}` with any of the fields above.
  `status`: `stored` (kept), `ready` (to sell or give away), `sold`, `given_away`, `discarded`.
- Delete (with its photos and listings): `DELETE /api/spaces/{space}/items/{id}`.

## Photos

- Add: `POST /api/spaces/{space}/items/{id}/photos`, `multipart/form-data` with two JPEG parts:
  `file` (at most 2048 px per edge and 2 MB) and `thumb` (at most 800 px per edge and 512 KB).
  An item holds at most 8 photos. Phone photos are usually larger, and HEIC/PNG must be converted, so make both
  files yourself from the original with ImageMagick (`-strip` removes EXIF, GPS included; the API refuses images
  that still carry EXIF, XMP or IPTC metadata with 422):
  `magick original.heic -auto-orient -strip -resize '2048x2048>' -quality 85 lamp.jpg` and
  `magick lamp.jpg -strip -resize '800x800>' -quality 80 lamp-thumb.jpg`. Do not use `sips`: it cannot remove
  metadata. For a JPEG made another way, `exiftool -all= -overwrite_original lamp.jpg` strips it.
  Check the sizes before uploading.

  ```bash
  curl -H "Authorization: Bearer $ZALEGA_TOKEN" -F file=@lamp.jpg -F thumb=@lamp-thumb.jpg \
    https://zalega.puniserv.pl/api/spaces/$SPACE/items/$ITEM/photos
  ```
- Reorder: `PATCH /api/spaces/{space}/items/{id}/photos` with `{"order": [every photo id, first one first]}`.
- Replace the image (e.g. to black out serial numbers, IMEI or MAC addresses): `POST /api/spaces/{space}/photos/{id}`
  with the same two parts as an upload. Id and position stay, `url` and `thumb_url` change; the old image is gone for good.
- Download: `GET /api/spaces/{space}/photos/{id}` (or `/thumb`). Delete: `DELETE /api/spaces/{space}/photos/{id}`.

## Listings (where an item is offered for sale)

- Add: `POST /api/spaces/{space}/listings` with `{"item_id": ..., "platform": "<key from /api/platforms>"}`; optional
  `title`, `description`, `url`, `price_listed`, `notes`, `status` (`draft` by default; `published`, `sold`, `expired`, `removed`).
- Edit: `PATCH /api/spaces/{space}/listings/{id}`. Setting `status` to `sold` closes the item: `sold` when
  `price_listed` is above 0, otherwise `given_away`. Send the final `price_listed` in the same request if it differs.
  The status and price of a sold listing cannot change any more.
- Record a refresh on the platform: `POST /api/spaces/{space}/listings/{id}/bump` (published listings only).
- Stale listings and counts per status: `GET /api/spaces/{space}/dashboard`.
- Delete: `DELETE /api/spaces/{space}/listings/{id}` (a sold listing cannot be deleted).

## Rules

- Confirm with the user before any DELETE.
- Read-only tokens get 403 `Access Denied.` on POST/PUT/PATCH/DELETE. Tell the user instead of retrying.
- Errors are JSON `{"error": "...", "errors": {"field": "message"}}`: 400 malformed body, 401 token invalid, expired or revoked
  (a password change revokes all tokens; ask the user for a new one), 403 not allowed (read-only token, owner-only action),
  404 not found or not your space, 422 validation or a business rule (fix the fields or tell the user), 429 rate limit (wait `Retry-After` seconds).
- Tokens cannot manage tokens, log in or out, change the password, or touch a space's members and invitations;
  those need the web app.
- Owner-only actions a token can do (renaming or deleting a space, the public page) are in openapi.yaml.
  Do them only when the user asks explicitly.
