Files
descrybe/docs/FEED_XML_JSON_V10.md
T
2026-10-15 21:22:43 +02:00

86 lines
5.3 KiB
Markdown

# Descrybe feed import/export — XML and JSON v10
## XML: supplier SHOPITEM records and nested attributes
Feeds with `<SHOP><SHOPITEM>…</SHOPITEM></SHOP>` are supported. Record path is detected as `SHOP/SHOPITEM`, and the sync parser recognizes `SHOPITEM` even if the UI has not saved a record path. `PRODUCT` inside `SHOPITEM` is treated as the product name, not an item wrapper.
Recommended EMOS mapping (auto-suggestions select available standard fields):
| Source | Target |
| --- | --- |
| `EAN` | `gtin` (required) |
| `PRODUCT` | `title` |
| `PRODUCTNO` | `sku` |
| `PRODUCTNO2` | `mpn` |
| `MANUFACTURER` | `brand` |
| `CATEGORY` | `category` (hierarchical supplier path retained) |
| `DESCRIPTION_BASIC` | `description` (the supplier's HTML) |
| `PARAMS` | `specifications` (nested named values) |
| `DESCRIPTION` | `specifications` (pipe-separated `label: value` fallback when `PARAMS` is unavailable) |
| `IMGURL` | `image_url` |
| `ADDITIONAL_IMAGE_URLS` | `additional_image_urls` |
| `PRICE_VAT` | `price` |
| `PRICE_VOC` | `purchase_price` |
| `AVAILABILITY` | `availability` |
| `URL` | `product_url` |
Every `PARAMS/PARAM` entry becomes its own `PARAMS/<normalized-name>` key, with its corresponding `VAL` and no value from any other `PARAM`. `ORDER` only affects the supplier's display order and is not imported as a technical attribute. Additional `IMGURL_ALTERNATIVE_XX` URLs are collected into `ADDITIONAL_IMAGE_URLS`.
For auto-mapping: open the feed's **Map fields** screen, extract schema, review suggested mappings, and apply. Required mappings appear first; newly added mapping rows are inserted at the top of the editable section. Approve proposed aliases when supplier semantics are ambiguous.
## JSON product feed (URL or file)
Create a feed using JSON and supply an HTTP URL or a local `.json` file. Supported shapes include:
```json
[{"ean":"8595025395184","name":"Lamp"}]
```
```json
{"data":{"products":[{"ean":"8595025395184","name":"Lamp","attributes":[{"name":"color","value":"white"}]}]}}
```
Also recognizes arrays named `products`, `items`, `results`, `records`, `shopitem`, `offers`, `entries`, and `data`. For unusual shapes, set the JSON product record path (e.g., `data/products`) on the mapping screen. Scalar fields use slash-separated nested paths, and repeated `[{name,value}]` attribute pairs become named specification children.
For the Sanotechnik example, use `https://datacore.sanotechnik.com/datacore/sanotechnik-products/?format=json`. The exact response shape could not be verified from the external endpoint; extract the schema and confirm the suggested item path and mappings before syncing the full feed.
## Authentication and headers
Feed creation/editing supports Bearer tokens, a named API-key header, and additional string-valued HTTP headers. Credentials are encrypted in existing `input_feeds.options`, not returned in feed DTOs. When editing a feed, leave header inputs blank to retain existing credentials. A redirect to another hostname strips all custom headers. HTTP and DNS targets are subject to the existing SSRF protections.
JSON URL catalog import for **products, categories, or attributes** is available in the respective catalog pages. These are bounded one-time imports using existing company-scoped CSV upserts and a **6 MiB** catalog upload limit. For large product catalogs, use an automatically synced JSON feed instead (existing max **256 MiB** download and **1,000,000** row guard).
Example one-time catalog request (requires a user session or supported authentication):
```http
POST /api/categories/import
Content-Type: application/json
{"url":"https://supplier.example/catalog/categories?format=json","format":"json","request_headers":{"X-API-Key":"YOUR_KEY"}}
```
Use `/api/attributes/import` or `/api/products/import` for those catalog types. Direct one-time product imports use the existing product catalog's core-field importer; nested specifications should be imported with a mapped JSON feed.
## JSON export
Select **Custom JSON** when creating an export feed. Generated JSON contains a configurable array root (default `products`); fields are mapped from Descrybe product data. JSON public feeds have paths:
```text
/api/public/export-feeds/<token>.json
```
The export stream writes records incrementally; the format choice is also honored for on-demand and selected-product exports. Do not share the public export URL as a secret credential: the URL token is the access mechanism, as with existing CSV/XML public exports.
## Deployment and verification
No SQL migration is needed for these features because feed type, export format, and encrypted source settings reuse existing TEXT/JSONB columns.
1. Deploy updated **API, worker and frontend** together.
2. Rebuild using **Go 1.25** (required by the project).
3. Create an XML `SHOPITEM` feed and verify named attributes survive sync; map EAN as GTIN.
4. Create a JSON feed and extract its schema; check the detected array path.
5. Create a Custom JSON export and fetch the generated `.json` URL.
6. Run the new Go parser/catalog regression tests and your normal integration suite.
Focused tests were run under an isolated Go 1.23 standard-library harness for parser and JSON-to-CSV helper files. Changed frontend scripts passed TypeScript syntax transpilation. The complete Go 1.25 application build, Svelte compiler build, and live Sanotechnik request were not verified in this environment.