My Pro AgendaKehittäjäportaali

API v2 ja OAuth 2.0

Yhdistä ohjelmistosi My Pro Agendaan: ajanvaraukset, asiakkaat, vapaat ajat, laskut, maksut — luku ja kirjoitus, jokaisen toimipaikan nimenomaisella suostumuksella.

1. Aloitus

  1. Luo sovellus portaalissa: saat client_id:n ja client_secretin (näytetään kerran).
  2. Ilmoita uudelleenohjaus-URL:t ja valitse tarvittavat scopet — pyydä vähintä.
  3. Ohjaa käyttäjä valtuutusnäkymään; hän valitsee toimipaikan ja hyväksyy. Saat koodin vaihdettavaksi tokeniin.
  4. Kutsu API:a otsakkeella ”Authorization: Bearer <access_token>”. Lähetä sovellus tarkistukseen julkaistavaksi markkinapaikalla.

2. OAuth 2.0

Authorization code + PKCE (suositus kaikille, pakollinen ilman palvelinta), refresh token (90 pv, kierto joka käytöllä, scope offline_access) ja client credentials jo asennetuille palvelinintegraatioille.

Vaihe 1 — Ohjaus valtuutusnäkymään

GET https://myproagenda.com/fi/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)

Vaihe 2 — Koodin vaihto (POST, x-www-form-urlencoded tai 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 apps

Vastaus

{ "access_token": "mpa2_…", "token_type": "Bearer", "expires_in": 3600,
  "refresh_token": "mpar_…", "scope": "appointments:read appointments:write offline_access",
  "establishment_id": "uuid" }

Uusinta (edellinen token perutaan)

POST https://myproagenda.com/api/oauth/token
grant_type=refresh_token&refresh_token=mpar_…&client_id=app_…[&client_secret=…]

Client credentials (olemassa oleva asennus)

POST https://myproagenda.com/api/oauth/token
grant_type=client_credentials&client_id=app_…&client_secret=mpas_…&establishment_id=uuid[&scope=…]

3. Scopet

Yksi scope per resurssi ja suunta. Toimipaikka näkee listan suostuessaan ja voi perua sovelluksen milloin tahansa (Asetukset → API ja webhookit → Sovellukset).

ScopeKuvaus
establishment:readEstablishment profile, timezone, currency
services:readServices and prices
resources:readCalendars (staff, rooms, equipment)
slots:readAvailable slots
appointments:readAppointments (incl. client identity)
appointments:writeCreate, update, cancel appointments
clients:readClient records
clients:writeCreate or update clients
invoices:readInvoices and quotes
payments:readPayments received
forms:readForms
reviews:readClient reviews
webhooks:manageReserved (webhook subscriptions managed by the app)
offline_accessRefresh token (long-lived access)

4. Päätepisteet

Perusosoite: https://myproagenda.com/api/v2

Kursorisivutetut listat: anna next_cursor ?cursor=-parametrina kunnes se on null (enint. 100/sivu). updated_since mahdollistaa inkrementaalisen synkronoinnin.

Idempotenssi: lähetä Idempotency-Key POST/PATCH-pyynnöissä; sama avain palauttaa alkuperäisen vastauksen 24 h (otsake Idempotent-Replayed: true).

MetodiPolkuScopeKuvaus
GET/establishmentestablishment:readCurrent establishment and granted scopes
GET/servicesservices:readServices
GET/resourcesresources:readCalendars (people and equipment)
GET/slotsslots:readAvailable slots
GET/appointmentsappointments:readAppointments (cursor-paginated, sorted by start)
POST/appointmentsappointments:writeCreate an appointment (same rules as online booking; client found or created by e-mail / mobile; notifications sent). Supports Idempotency-Key.
GET/appointments/{id}appointments:readAppointment detail
PATCH/appointments/{id}appointments:writeUpdate status / note
DELETE/appointments/{id}appointments:writeCancel (client notified unless notify=false)
POST/appointments/{id}/cancelappointments:writeCancel (alias of DELETE for clients that cannot send a body with DELETE)
GET/clientsclients:readClients (cursor-paginated, sorted by creation)
POST/clientsclients:writeCreate or update a client (deduplicated by e-mail / mobile). Supports Idempotency-Key.
GET/clients/{id}clients:readClient detail
PATCH/clients/{id}clients:writeUpdate a client
GET/invoicesinvoices:readInvoices
GET/invoices/{id}invoices:readInvoice detail
GET/paymentspayments:readPayments received
GET/formsforms:readForms
GET/reviewsreviews:readReviews
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. Webhookit

Ilmoita https-URL sovelluksessasi: jokainen asentaneiden toimipaikkojen tapahtuma lähetetään allekirjoitettuna JSON-POSTina webhook_secretilläsi.

Otsakkeet

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": { … } }

Tarkistus (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');

Tapahtumat

appointment.createdappointment.rescheduledappointment.cancelledappointment.status_changedappointment.updatedappointment.deletedclient.createdclient.updatedpayment.receivedinvoice.createdreview.createdapp.ping

Toimitus: uusinta virheessä (enint. 6 yritystä), tapahtumat säilytetään 30 pv, testaa ”Lähetä ping” portaalissa.

6. Virheet ja rajat

Virhemuoto:

{ "error": { "code": "FORBIDDEN_SCOPE", "message": "The token does not include the scope required by this endpoint" } }
HTTPKoodiMerkitys
401UNAUTHORIZED / TOKEN_EXPIREDMissing, invalid, revoked or expired token
403FORBIDDEN_SCOPEToken lacks the required scope
400VALIDATION / INVALID_CURSORMalformed payload or cursor; message lists the fields
404NOT_FOUND / UNKNOWN_ACTIONUnknown resource or endpoint
409STATE / SLOT_TAKEN / TOO_SOON / DOC_REQUIREDBusiness rule prevents the operation
429RATE_LIMITToo many requests
500ERRORUnexpected error (retry later)

Rajat: 1 000 pyyntöä/min ja 60 000/pv per sovellus ja toimipaikka (429 RATE_LIMIT); token 1 h; koodi 10 min; ei CORSia (vain palvelin).

7. v1-avaimet

Toimipaikan luomat v1-avaimet (mpa_…) pysyvät voimassa ja toimivat myös /api/v2:ssa. Useille toimipaikoille jaettavaan sovellukseen käytä OAuthia.

API v2 ja OAuth 2.0 — My Pro Agenda · My Pro Agenda