---
name: fototilbud-api
description: Work with Befaringsappen (befaringsappen.no), a Norwegian photo-to-quote service for plumbers. Use to read incoming quote requests, inspect the AI analysis and photos, edit and price quote drafts, approve quotes, record outcomes, and verify FotoTilbud webhooks, for example when connecting FotoTilbud to an order, CRM or invoicing system.
---

# Befaringsappen API

Base URL: https://befaringsappen.no
Human-readable guide (Norwegian): https://befaringsappen.no/utviklere

A customer sends photos of a plumbing job. An AI model maps the photos to items in the company's own price list. Befaringsappen's pricing engine computes the total. The plumber reviews, edits and approves the quote, and sends it to the customer by SMS.

## Rules for agents

- Money is always integer øre (1 kr = 100 øre). Price list prices are ex VAT. Fields ending in `IncVatOre` include 25 % VAT.
- Never invent prices. Quote lines refer to price list items by `itemId`, and the server computes every total.
- `POST /api/v1/requests/:id/approve` locks a quote that goes to a real customer. Call it only when the company user has explicitly asked you to approve that request.
- `POST /api/v1/me/rotate-key` invalidates the key you are using. Call it only on explicit request.
- Customer names, phone numbers and addresses are personal data. Do not copy them anywhere the task does not need them.
- Error responses are JSON `{ "error": "<code>", "message": "<Norwegian text>" }`. Show the message to Norwegian-speaking users as is.

## Typical workflow

1. `GET /api/v1/requests?status=ready` to find requests whose AI analysis is done. `needs_visit` means the job needs a site visit, not a photo quote.
2. `GET /api/v1/requests/:id` for the AI analysis (`request.analysis`), the current draft (`request.draft`), its computed price (`priced`, or `pricingError`) and the job type (`job`). Photos are at `/api/v1/requests/:id/photos/0`, `/1` and so on.
3. Change lines with `PUT /api/v1/requests/:id/draft`. The response contains the new computed price.
4. When the user approves, `POST /api/v1/requests/:id/approve` and give them the returned `sms.href` (opens their SMS app) or `quoteUrl`.
5. When the job is won or lost, `POST /api/v1/requests/:id/outcome`.

## Endpoints

### Company API

Authorization: Bearer ft_… (the company's API key).

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/me` | Company settings, including price list, form URL and embed snippets |
| PATCH | `/api/v1/me` | Update settings such as priceList, webhookUrl, paused, dailyRequestLimit, urgentAlerts, urgentAlertPhone serviceArea ("8000-8099, 8200" or [{ from, to }]) or partsCatalog (purchase prices) |
| POST | `/api/v1/me/rotate-key` | Issue a new API key. The old key stops working immediately |
| GET | `/api/v1/catalog` | Job types (photo steps, questions, site-visit rules) and the price list |
| GET | `/api/v1/requests` | List requests. Filter with ?status= |
| GET | `/api/v1/requests/:id` | One request with the AI analysis, draft, priced draft and the parts list's purchase cost (partsCost) |
| GET | `/api/v1/requests/:id/photos/:index` | Photo number :index (zero-based) |
| PUT | `/api/v1/requests/:id/draft` | Save the draft and get it priced again |
| POST | `/api/v1/requests/:id/analyze` | Run the AI analysis again |
| POST | `/api/v1/requests/:id/approve` | Lock the quote. Returns quoteUrl and a ready SMS { to, text, href } |
| POST | `/api/v1/requests/:id/outcome` | Record the outcome: { outcome: "won" \| "lost" \| null } |

### Website

Authorization: Bearer ft_… (the company's API key). Texts and pictures on the company's own website.

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/site` | The content (texts, contact, pictures per place and service) and the picture library with public links |
| PUT | `/api/v1/site` | Save the content: { texts, contact, images: { hero, about }, services: { <id>: { desc, image } } }. Empty text means the website's default |
| POST | `/api/v1/site/media` | Upload a picture (multipart: file, alt). JPEG, PNG or WebP, max 6 MB |
| POST | `/api/v1/site/media/:id/delete` | Delete a picture. Places that used it go back to the default |

### Social media

Authorization: Bearer ft_… (the company's API key). The AI drafts posts; only posts you approve are published.

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/social` | Settings, connected accounts and all posts (drafts, scheduled, posted) |
| PATCH | `/api/v1/social/settings` | Update { postsPerWeek, weekdays (1–7), time (HH:MM), platforms, websiteUrl, area } |
| POST | `/api/v1/social/connect/:platform` | Link where the company signs in and connects the network (facebook, instagram, x) |
| POST | `/api/v1/social/accounts/refresh` | Fetch which accounts are connected, after signing in |
| POST | `/api/v1/social/plan` | Have the AI write drafts for the free slots in the next two weeks |
| PATCH | `/api/v1/social/posts/:id` | Edit { text, platforms, mediaUrl, scheduledAt }. Any change needs a new approval |
| POST | `/api/v1/social/posts/:id/approve` | Approve the post for its scheduled time, or { now: true } to post now |
| POST | `/api/v1/social/posts/:id/reject` | Discard the post |

### Platform API

Authorization: Bearer <PLATFORM_API_KEY>. For host systems that create companies for their customers.

| Method | Path | What it does |
|---|---|---|
| POST | `/api/v1/tenants` | Create a company: { slug, settings }. The API key is returned only in this response |

### Public API (custom customer form)

No key. Use these to build your own form instead of embedding ours.

| Method | Path | What it does |
|---|---|---|
| GET | `/api/public/:slug/config` | Company name, colours, job types with photo steps and questions, and the categories for "what do you need help with?" |
| GET | `/api/public/:slug/site` | The company's website content: texts, contact and picture links. An empty field means the website's default |
| GET | `/api/public/:slug/media/:file` | A picture from the company's picture library (also used in Instagram posts) |
| POST | `/api/public/:slug/requests` | Submit a request as multipart/form-data, with photos in fields named photo:<stepId>. Optional choice: the id of the category choice. Choices under Akutt send an SMS alert to the plumber |
| GET | `/api/public/status/:token` | The customer's own status: the AI's note to the customer, whether a site visit is needed and whether the quote is sent. No prices. statusToken comes in the submit response and in fototilbud:submitted |
| POST | `/api/public/quotes/:token/respond` | The customer's answer to a quote: { action: "accept" \| "decline", startEarly? } |

Request statuses: `received`, `analyzing`, `ready`, `needs_visit`, `analysis_failed`, `sent`, `accepted`, `declined`.

### Draft format (PUT /api/v1/requests/:id/draft)

```json
{
  "mode": "pristilbud",
  "lines": [
    { "itemId": "batteri-kjokken-arbeid", "qtyLow": 1, "qtyHigh": 1 },
    { "custom": { "label": "Ekstra kobling", "unit": "stk", "priceExVatOre": 25000, "kind": "materiell" }, "qtyLow": 1, "qtyHigh": 2 }
  ],
  "customerNote": "",
  "internalNote": ""
}
```

- `mode` is `"pristilbud"` (binding price) or `"prisoverslag"` (estimate; by Norwegian law the final price may exceed it by at most 15 %).
- Each line has either `itemId` (from `GET /api/v1/catalog`) or `custom`, never both. `qtyLow` must not exceed `qtyHigh`. Use a range when the photos leave the quantity uncertain.
- `priceOverrideExVatOre` (optional) replaces the price list price for that line. At most 50 lines.

## Embedding the customer form

`<script src="https://befaringsappen.no/embed.js" data-fototilbud="<slug>" data-mode="widget" async></script>` adds a chat-style launcher that opens the form in a panel. With `data-launcher="none"` there is no launcher, and a livechat or button opens it with `FotoTilbud.open({ job, name, phone, email, address, postcode, description })`. All fields are optional and only fill empty fields; the customer still reviews and submits. The window event `fototilbud:submitted` (detail `{ requestId, jobKey, slug }`) fires when the customer has sent. Other modes: inline (default) and `data-mode="button"`. All options: https://befaringsappen.no/utviklere#innbygging

## Webhooks

Set `webhookUrl` with `PATCH /api/v1/me`. Each event is POSTed as JSON:

`{ id, type, createdAt, tenantId, requestId, data }`

| Event | When | data |
|---|---|---|
| `request.created` | A customer submitted photos | jobKey, customer, choice, urgent |
| `request.analyzed` | The AI analysis finished or failed | status, needsSiteVisit, overallConfidence, error |
| `quote.sent` | The quote was approved and locked | quoteUrl, number, mode, totalIncVatOre, validUntil |
| `quote.accepted` | The customer accepted the quote | number, totalIncVatOre, startEarlyConsent, customer |
| `quote.declined` | The customer declined the quote | number, totalIncVatOre, startEarlyConsent, customer |

Headers: `X-Fototilbud-Event: <type>` and `X-Fototilbud-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(webhookSecret, "<t>.<raw body>")>`. The `webhookSecret` is in `GET /api/v1/me`. Answer with a 2xx status within 10 seconds. Delivery is tried up to 3 times (immediately, after 5 s, after 30 s), so handle repeats by event `id`.

Verify every event before trusting it (Node.js):

```js
import { createHmac, timingSafeEqual } from "node:crypto";

// rawBody: the request body exactly as received, before JSON.parse
export function verifySignature(rawBody, signatureHeader, webhookSecret, toleranceSec = 300) {
  const parts = Object.fromEntries(String(signatureHeader).split(",").map((p) => p.split("=")));
  const t = Number(parts.t);
  if (!Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > toleranceSec) return false;
  const expected = createHmac("sha256", webhookSecret).update(`${t}.${rawBody}`).digest();
  const received = Buffer.from(parts.v1 ?? "", "hex");
  return received.length === expected.length && timingSafeEqual(received, expected);
}
```

## Errors

| Status | error | Meaning |
|---|---|---|
| 400 | `invalid` | Bad input. message says what |
| 401 | `unauthorized` | Missing or invalid key |
| 403 | `paused` | The company has paused its form |
| 404 | `not_found` | Does not exist, or belongs to another company |
| 409 | `conflict` | The customer already answered, or the slug is taken |
| 410 | `expired` | The quote has expired |
| 413 | `invalid` | The photos are too large in total |
| 429 | `rate_limited / daily_limit` | Too many requests. See the limits below |

## Limits

- Up to 12 photos per request, each at most 4.5 MB, 60 MB in total. JPEG, PNG or WebP.
- Request submissions: 6 per hour per IP address per company.
- Quote responses: 20 per hour per IP address.
- Each company accepts up to dailyRequestLimit requests in any 24 hours (30 by default, settable from 1 to 1000).
