API v2 og OAuth 2.0
Koble programvaren din til My Pro Agenda: avtaler, kunder, ledige tider, fakturaer, betalinger — lesing og skriving, med uttrykkelig samtykke fra hver virksomhet.
1. Kom i gang
- Opprett en app på portalen: du får client_id og client_secret (vises én gang).
- Angi redirect-URL-ene dine og velg nødvendige scopes — be om minst mulig.
- Send brukeren til autorisasjonsskjermen; de velger virksomhet og godtar. Du får en kode som byttes mot et token.
- Kall API-et med «Authorization: Bearer <access_token>». Send appen til gjennomgang for å publisere den på markedsplassen.
2. OAuth 2.0
Authorization code med PKCE (anbefalt for alle apper, påkrevd uten server), refresh token (90 dager, rotasjon ved hver bruk, scope offline_access) og client credentials for allerede installerte serverintegrasjoner.
Trinn 1 — Omdirigering til autorisasjonsskjermen
GET https://myproagenda.com/nb/oauth/authorize?client_id=app_…&redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
&scope=appointments%3Aread%20appointments%3Awrite%20offline_access&state=RANDOM
&code_challenge=BASE64URL(SHA256(code_verifier))&code_challenge_method=S256
→ redirect_uri?code=mpac_…&state=RANDOM (or ?error=access_denied)Trinn 2 — Bytt koden (POST, x-www-form-urlencoded eller JSON)
POST https://myproagenda.com/api/oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=mpac_…&redirect_uri=https://app.example.com/callback
&client_id=app_…&code_verifier=… # or client_secret=mpas_… for confidential appsSvar
{ "access_token": "mpa2_…", "token_type": "Bearer", "expires_in": 3600,
"refresh_token": "mpar_…", "scope": "appointments:read appointments:write offline_access",
"establishment_id": "uuid" }Forny (forrige token trekkes tilbake)
POST https://myproagenda.com/api/oauth/token
grant_type=refresh_token&refresh_token=mpar_…&client_id=app_…[&client_secret=…]Client credentials (eksisterende installasjon)
POST https://myproagenda.com/api/oauth/token
grant_type=client_credentials&client_id=app_…&client_secret=mpas_…&establishment_id=uuid[&scope=…]3. Scopes
Ett scope per ressurs og retning. Virksomheten ser listen ved samtykke og kan trekke appen tilbake når som helst (Innstillinger → API og webhooks → Apper).
| Scope | Beskrivelse |
|---|---|
establishment:read | Establishment profile, timezone, currency |
services:read | Services and prices |
resources:read | Calendars (staff, rooms, equipment) |
slots:read | Available slots |
appointments:read | Appointments (incl. client identity) |
appointments:write | Create, update, cancel appointments |
clients:read | Client records |
clients:write | Create or update clients |
invoices:read | Invoices and quotes |
payments:read | Payments received |
forms:read | Forms |
reviews:read | Client reviews |
webhooks:manage | Reserved (webhook subscriptions managed by the app) |
offline_access | Refresh token (long-lived access) |
4. Endepunkter
Base: https://myproagenda.com/api/v2
Cursor-paginerte lister: send next_cursor som ?cursor= til den er null (maks 100 per side). updated_since gir inkrementell synkronisering.
Idempotens: send Idempotency-Key på POST / PATCH; samme nøkkel gir det opprinnelige svaret i 24 t (header Idempotent-Replayed: true).
| Metode | Sti | Scope | Beskrivelse |
|---|---|---|---|
| GET | /establishment | establishment:read | Current establishment and granted scopes |
| GET | /services | services:read | Services |
| GET | /resources | resources:read | Calendars (people and equipment) |
| GET | /slots | slots:read | Available slots |
| GET | /appointments | appointments:read | Appointments (cursor-paginated, sorted by start) |
| POST | /appointments | appointments:write | Create an appointment (same rules as online booking; client found or created by e-mail / mobile; notifications sent). Supports Idempotency-Key. |
| GET | /appointments/{id} | appointments:read | Appointment detail |
| PATCH | /appointments/{id} | appointments:write | Update status / note |
| DELETE | /appointments/{id} | appointments:write | Cancel (client notified unless notify=false) |
| POST | /appointments/{id}/cancel | appointments:write | Cancel (alias of DELETE for clients that cannot send a body with DELETE) |
| GET | /clients | clients:read | Clients (cursor-paginated, sorted by creation) |
| POST | /clients | clients:write | Create or update a client (deduplicated by e-mail / mobile). Supports Idempotency-Key. |
| GET | /clients/{id} | clients:read | Client detail |
| PATCH | /clients/{id} | clients:write | Update a client |
| GET | /invoices | invoices:read | Invoices |
| GET | /invoices/{id} | invoices:read | Invoice detail |
| GET | /payments | payments:read | Payments received |
| GET | /forms | forms:read | Forms |
| GET | /reviews | reviews:read | Reviews |
curl "https://myproagenda.com/api/v2/appointments?from=2026-12-01T00:00:00Z&limit=50" -H "Authorization: Bearer mpa2_…"
curl -X POST https://myproagenda.com/api/v2/appointments -H "Authorization: Bearer mpa2_…" \
-H "Content-Type: application/json" -H "Idempotency-Key: 7f3c…" \
-d '{"service_id":"…","starts_at":"2026-12-03T09:00:00Z","last_name":"DUPONT","first_name":"Marie","mobile":"+33612345678","email":"marie@example.com"}'5. Webhooks
Angi en https-URL i appen din: hver hendelse fra virksomheter som installerte den sendes som signert JSON-POST med din webhook_secret.
Headere
POST https://app.example.com/webhooks/mpa
Content-Type: application/json
X-MPA-Timestamp: 1800000000
X-MPA-Signature-V2: t=1800000000,v1=<hex hmac-sha256(webhook_secret, "<t>.<raw body>")>
{ "id": 123, "event": "appointment.created", "establishment_id": "uuid", "created_at": "…", "data": { … } }Verifisering (Node.js)
const crypto = require('crypto');
const [t, v1] = req.headers['x-mpa-signature-v2'].split(',').map((p) => p.split('=')[1]);
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) throw new Error('stale');
const expected = crypto.createHmac('sha256', WEBHOOK_SECRET).update(`${t}.${rawBody}`).digest('hex');
if (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(v1))) throw new Error('bad signature');Hendelser
appointment.createdappointment.rescheduledappointment.cancelledappointment.status_changedappointment.updatedappointment.deletedclient.createdclient.updatedpayment.receivedinvoice.createdreview.createdapp.pingLevering: nytt forsøk ved feil (opptil 6), hendelser lagret 30 dager, test med «Send ping» på portalen.
6. Feil og grenser
Feilformat:
{ "error": { "code": "FORBIDDEN_SCOPE", "message": "The token does not include the scope required by this endpoint" } }| HTTP | Kode | Betydning |
|---|---|---|
| 401 | UNAUTHORIZED / TOKEN_EXPIRED | Missing, invalid, revoked or expired token |
| 403 | FORBIDDEN_SCOPE | Token lacks the required scope |
| 400 | VALIDATION / INVALID_CURSOR | Malformed payload or cursor; message lists the fields |
| 404 | NOT_FOUND / UNKNOWN_ACTION | Unknown resource or endpoint |
| 409 | STATE / SLOT_TAKEN / TOO_SOON / DOC_REQUIRED | Business rule prevents the operation |
| 429 | RATE_LIMIT | Too many requests |
| 500 | ERROR | Unexpected error (retry later) |
Grenser: 1 000 forespørsler/min og 60 000/dag per app og virksomhet (429 RATE_LIMIT); token 1 t; kode 10 min; ingen CORS (kun server).
7. v1-nøkler
v1-nøkler (mpa_…) opprettet av en virksomhet er fortsatt gyldige og fungerer også på /api/v2. Bruk OAuth for en app til flere virksomheter.
