# Make integration

There are two ways to use it: (A) generic HTTP modules, which work today, or (B) the Tricid custom
app definition in `integrations/make-app/`.

## A. HTTP modules (no app needed)

**Connection**: none. Put the token in a header on each module, or store it as a scenario variable.

1. **Create an image**: module *HTTP → Make a request*
   - URL `https://render.example.com/api/rest/images`, method `POST`
   - Headers: `Authorization: Bearer <token>`, `Content-Type: application/json`, and optionally `Idempotency-Key: {{executionId}}-{{bundle}}`
   - Body type *Raw*, content type *JSON*:
     ```json
     { "template_uuid": "abc123def456x",
       "layers": { "TITLE": { "text": "{{1.title}}" }, "PIC": { "image": "{{1.photo_url}}" } },
       "webhook_success": "https://hook.eu1.make.com/<your custom webhook>",
       "passthrough": "{{1.id}}" }
     ```
   - *Parse response*: yes. You get `id`, `status: queued` and `polling_url`.
2. **Get the result**, either way:
   - **Webhook (recommended)**: a second scenario that starts with *Webhooks → Custom webhook*. Either use its URL as
     `webhook_success` per job, or subscribe it once for **every** job in the project:
     `curl -X POST $BASE/api/rest/webhooks -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{"url":"<custom webhook URL>","events":["*.finished"]}'`. It receives the finished job (`image_url`/`pdf_url`/`video_url`, `passthrough`, …).
     It is a POST with a signed body (see code-samples.md §7). Make's custom webhook cannot check the
     HMAC itself. If you need verification, route through the n8n Trigger or your own endpoint.
   - **Polling**: *Tools → Repeater* (e.g. 30×) → *Tools → Sleep* 2 s → *HTTP → Make a request*
     `GET {{polling_url}}` with the same header. Then a *Filter* `status = finished` and a *Break* / *Array aggregator*.
3. **Upload media**: *HTTP → Make a request*, `POST /api/rest/media`, body type *multipart/form-data*,
   field `file` (type *File*). The response holds `media[].file_id` (a URL for picture layers).

PDFs and videos work the same way, with `POST /api/rest/pdfs` (`pages[]`) and `/api/rest/videos` (`clips[]`).

## B. Custom app: `integrations/make-app/`

This is a definition in Make's custom-app format: `base.imljson`, `connection/`, `rpcs/`, `functions/`, `modules/`, `webhooks/`.

| Action | Tricid app |
|---|---|
| Create Image / PDF / Video | `createImage`, `createPdf`, `createVideo`. A template select with **dynamic layer fields** (RPC `layerFields` + IML function `layerSpec`, one collection per dynamic layer with that type's properties); optional wait-for-file via `repeat` polling |
| Upload Media | `uploadMedia` (multipart) |
| Watch Image / PDF / Video (instant) | `watchJobs`: an **attached** webhook. When the trigger is created, Make subscribes it as a project webhook (`POST /api/rest/webhooks`, events chosen in the trigger, e.g. `image.finished`). When it is deleted, Make unsubscribes it (`DELETE /api/rest/webhooks/{id}`). It sees **every** matching job in the project |
| — | `getJob` (by kind + id) |

Connection: Base URL + API token. The token is sanitised from logs.

**How to load it**: create a custom app in Make (Make → Custom apps, or the "Make Apps Editor" VS Code
extension), then paste each file into the matching section. `node integrations/make-app/scripts/check.mjs`
checks offline that every file parses and that `layerSpec` builds the fields. `scripts/generate.mjs`
regenerates the module files.

**Status: draft.** It has not been validated in Make's app builder: no Make account was available. The
directive details most likely to need adjustment are:
- `pagination.url`
- `repeat.condition`
- the `rpc://…?__kind=` parameter
- `emptycollection`

Make's webhook step cannot verify the HMAC signature itself. Each subscription has its own secret, so if you need verification, route through the n8n Trigger or your own endpoint.
