Developer portal

Documentation

Base URL https://theplanarfoundry.com/api/v1/public. The endpoint reference below is generated from the live OpenAPI schema.

Getting started

1. Register an application under Applications and activate it. 2. Generate an API key (you will be asked to confirm your password). 3. Call the API:

curl -H "Authorization: Bearer $PF_API_KEY" https://theplanarfoundry.com/api/v1/public/app

Authentication & API keys

API keys (pf_live_…) act as the application owner with ordinary member rights: public data plus the owner's own resources. Staff authority never passes through credentials. Send keys only in the Authorization header; keys in URLs are rejected. Server apps can exchange a client secret for a 15-minute app token:

curl -X POST https://theplanarfoundry.com/api/v1/public/oauth/token -d grant_type=client_credentials \
  -d client_id=$CLIENT_ID -d client_secret=$CLIENT_SECRET -d "scope=cards:read"

OAuth2: act for other members (Authorization Code + PKCE)

Server and browser apps can ask any member for consent. Register exact redirect URIs (https; http only for localhost; no wildcards). Generate a PKCE verifier (43–128 chars) and its S256 challenge, then send the user to:

https://theplanarfoundry.com/api/v1/public/oauth/authorize?response_type=code&client_id=$CLIENT_ID
  &redirect_uri=https%3A%2F%2Fyour.app%2Fcallback&scope=cards%3Aread%20decks%3Aread
  &state=$RANDOM_STATE&code_challenge=$CHALLENGE&code_challenge_method=S256

After consent the user returns with ?code=…&state=… (code valid 2 minutes, single use). Exchange it (server apps also send client_secret):

curl -X POST https://theplanarfoundry.com/api/v1/public/oauth/token -d grant_type=authorization_code -d client_id=$CLIENT_ID \
  -d code=$CODE -d redirect_uri=https://your.app/callback -d code_verifier=$VERIFIER

You receive a 1-hour pf_ut_… access token and a 30-day pf_rt_… refresh token. Every refresh returns a new refresh token; reusing an old one revokes the whole sign-in. Revoke with POST /oauth/revoke token=…. Users can disconnect apps in Settings → Connected apps. Write, manage and participate scopes need staff approval before users can grant them.

curl -X POST https://theplanarfoundry.com/api/v1/public/oauth/token -d grant_type=refresh_token -d client_id=$CLIENT_ID -d refresh_token=$REFRESH

Pagination & filtering

Collections return {data, pagination: {next_cursor, has_more, page_size}}. Pass limit (1–100) and the opaque, signed cursor. Sort with sort=name or sort=-created_at where documented.

curl -H "Authorization: Bearer $KEY" "https://theplanarfoundry.com/api/v1/public/cards/custom?limit=50&sort=name"
curl -H "Authorization: Bearer $KEY" "https://theplanarfoundry.com/api/v1/public/cards/custom?limit=50&sort=name&cursor=$NEXT"

Errors

Every error uses one envelope with a request ID you can quote to support. 404 is also returned when you may not see a resource.

{"error": {"code": "insufficient_scope", "message": "…", "request_id": "…", "details": {"missing": ["decks:read"]}}}

Rate limits

Limits apply per IP, per application, per acting user and to writes (defaults: 300/min IP, 120/min app, 240/min user, 30 writes/min). Responses carry X-RateLimit-Limit/Remaining/Reset; a 429 includes Retry-After. Staff may set lower limits for an app.

Webhooks

Subscribe an HTTPS endpoint to events on an application's Webhooks panel (or POST /public/webhooks with an app credential). The app needs webhooks:manage plus the read scope of each event. Events are delivered only when the application owner can currently see the resource as an ordinary member (public items, their own items, communities they belong to; staff-only community events need the matching community role). Revoking access, removing a scope, suspending the app or leaving a community stops future deliveries.

POST https://your.app/foundry-webhooks
Content-Type: application/json
Foundry-Event-Id: evt_…          (stable across retries: deduplicate on it)
Foundry-Event-Type: tournament.match.confirmed
Foundry-Delivery-Id: whd_…   Foundry-Delivery-Attempt: 1
Foundry-Timestamp: 1760000000
Foundry-Signature: t=1760000000,v1=<hex>[,v1=<hex during secret rotation>]

{"id":"evt_…","object":"event","type":"…","api_version":"v1","created_at":"…",
 "resource":{"type":"match","id":"mt_…"},"data":{…},"test":false,
 "context":{"app_id":"app_…","subscription_id":"whsub_…"}}

Verify every request: HMAC-SHA256 of <timestamp>.<raw body> with your whsec_… secret, constant-time compare, and reject timestamps older than 5 minutes. Use the raw bytes, not re-serialised JSON.

import hmac, hashlib, time

def verify(secret: str, header: str, raw_body: bytes, tolerance=300) -> bool:
    parts = [p.split("=", 1) for p in header.split(",") if "=" in p]
    ts = next((v for k, v in parts if k == "t"), "")
    if not ts.isdigit() or abs(time.time() - int(ts)) > tolerance:
        return False  # stale or replayed
    expected = hmac.new(secret.encode(), f"{ts}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(expected, v) for k, v in parts if k == "v1")
const crypto = require("crypto");
function verify(secret, header, rawBody, tolerance = 300) {
  const parts = header.split(",").map((p) => p.split("="));
  const ts = (parts.find(([k]) => k === "t") || [])[1];
  if (!/^\d+$/.test(ts || "") || Math.abs(Date.now() / 1000 - Number(ts)) > tolerance) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${ts}.`).update(rawBody).digest("hex");
  return parts.some(([k, v]) => k === "v1" && v.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
}
  • At-least-once, not exactly-once. Store processed Foundry-Event-Ids and ignore repeats; answer 2xx quickly and process asynchronously.
  • Ordering is not guaranteed. Events carry created_at; refetch the resource from the API (see data.links.api) when order matters.
  • Retries: 10 s timeout, 8 attempts with exponential backoff (1 min, 5 min, 30 min, 2 h, 6 h, 12 h, 24 h, ±10% jitter), then dead-letter. Retry dead or skipped deliveries from the delivery history. After 5 days of failures with no success the subscription pauses and the owner is notified; resume it from the portal.
  • Redirects are never followed. Destinations must be public HTTPS; loopback, private, link-local, CGNAT, reserved and cloud-metadata addresses are refused, and DNS is re-checked before every attempt.
  • Rotate the signing secret any time; the previous secret keeps signing (a second v1) for 0–72 hours. Test events (webhook.test, "test": true) change no records. History is kept 30 days.
  • card.created (cards:read) A custom card was created (private and unlisted cards reach only their owner's apps)
  • card.updated (cards:read) A custom card was revised (new version)
  • card.published (cards:read) A custom card became public and published
  • card.submission.created (communities:read) A card was submitted to a community (submitter and community reviewers only)
  • card.submission.approved (communities:read) A community approved a card submission into a collection
  • card.submission.rejected (communities:read) A community rejected a card submission
  • mechanic.updated (mechanics:read) A mechanic version was approved and published (first approval included)
  • ruling.published (rulings:read) A ruling was published
  • ruling.superseded (rulings:read) A published ruling was superseded by a newer one
  • community.updated (communities:read) A community page was updated
  • community.member.joined (communities:read) A member joined a community
  • format.updated (formats:read) A custom format was updated or published
  • tournament.created (tournaments:read) A tournament was created
  • tournament.registration.opened (tournaments:read) Registration opened (tournaments open registration when created)
  • tournament.player.registered (tournaments:read) A player registered or joined the waitlist
  • tournament.match.reported (tournaments:read) A player reported a tournament match result
  • tournament.match.confirmed (tournaments:read) A tournament match result was confirmed or settled
  • tournament.standings.updated (tournaments:read) Tournament standings changed after a result
  • tournament.completed (tournaments:read) A tournament finished
  • league.created (leagues:read) A league was created (visible to others once approved)
  • league.season.started (leagues:read) A league season started
  • league.match.confirmed (leagues:read) A league match result was confirmed or settled
  • league.standings.updated (leagues:read) League season standings changed

Security recommendations

  • Keep keys and client secrets on servers; browser and mobile apps use PKCE without secrets.
  • Request the fewest scopes you need; rotate credentials regularly and before staff changes.
  • Always send and check state; store refresh tokens encrypted; never log tokens.
  • Revoke credentials immediately if exposed: staff can also revoke compromised credentials.

Scope reference

  • cards:read Read public cards and the app owner's own cards
  • cards:write Create and edit the app owner's own cards
  • decks:read Read public decks and the app owner's own decks
  • decks:write Create and edit the app owner's own decks
  • mechanics:read Read mechanics and keyword references
  • rulings:read Read card rulings
  • communities:read Read public communities (and ones the owner belongs to)
  • communities:manage Manage communities where the owner holds a qualifying community role
  • formats:read Read formats
  • formats:manage Manage the owner's custom formats
  • tournaments:read Read tournaments
  • tournaments:manage Run tournaments the owner organises
  • tournaments:participate Register, check in, withdraw and report/confirm results as the app owner (player actions)
  • leagues:read Read leagues
  • leagues:manage Run leagues the owner commissions
  • leagues:participate Enroll, withdraw and log/confirm league matches as the app owner (player actions)
  • stats:read Read public statistics
  • webhooks:manage Manage the application's webhook subscriptions (each event also needs its read scope)
  • communities:participate Join and leave communities as the acting user
  • mechanics:write Propose and revise mechanics as the acting user (independent review still applies)
  • rulings:write Add creator explanations, community house rulings or Foundry ruling proposals, and withdraw them
  • rules:review Review mechanics and rulings, only if the acting user already holds the Rules Reviewer permission or a community rulings role

Endpoint reference

Public API · metadata

  • GET/webhook-eventsWebhook event catalog (no authentication)

Public API · Webhooks

  • GET/webhooksList webhook subscriptions
  • POST/webhooksCreate a webhook subscription (signing secret returned once)
  • GET/webhooks/{sid}One webhook subscription
  • PATCH/webhooks/{sid}Update a webhook subscription
  • DELETE/webhooks/{sid}Delete a webhook subscription
  • POST/webhooks/{sid}/disableDisable a subscription
  • POST/webhooks/{sid}/resumeResume a paused or disabled subscription
  • POST/webhooks/{sid}/rotate-secretRotate the signing secret (new secret returned once)
  • POST/webhooks/{sid}/testSend a test event
  • GET/webhooks/{sid}/deliveriesDelivery history
  • GET/webhook-deliveries/{did}One delivery with attempts and payload
  • POST/webhook-deliveries/{did}/retryRetry a failed delivery once

Public API

  • GET/scopesAvailable permission scopes (no authentication)
  • GET/appThe calling application's identity
  • GET/app/credentialsCredential metadata for this application (cursor paginated, no secrets)
  • POST/oauth/tokenOAuth2 token endpoint: client_credentials, authorization_code (+PKCE S256) and refresh_token (rotating)
  • POST/oauth/revokeRFC 7009 token revocation (access or refresh token; always 200)
  • GET/oauth/authorizeStart user authorization (Authorization Code + PKCE S256): redirects to the consent screen

Public API · Cards & decks

  • GET/cards/officialSearch official Magic cards (Scryfall). Pages follow Scryfall's page size (up to 175).
  • GET/cards/official/{scryfall_id}An official card by Scryfall ID (optionally with its published rulings)
  • GET/card-typesCard categories and special types, with the Multiverse Companion mode each special type belongs to
  • GET/cards/customSearch custom cards: public library, or the app owner's own cards with owner=me
  • POST/cards/customCreate a custom card owned by the app owner (website validation applies)
  • GET/cards/custom/{card_id}A custom card with communities and format-legality references
  • PATCH/cards/custom/{card_id}Update one of the app owner's cards (creates a new version)
  • GET/cards/custom/{card_id}/versionsRevision history of a custom card (newest first)
  • GET/cards/{identity}/rulingsOracle text and rulings for official:<scryfall_id> or custom:<card_id>
  • GET/decksPublished public decks, or the app owner's decks with owner=me
  • POST/decksCreate a deck owned by the app owner
  • GET/decks/{deck_id}A deck: zones (main, sideboard, commander, planar, scheme, vanguard…), resolved cards, stats and legality
  • PATCH/decks/{deck_id}Update one of the app owner's decks (format validation applies)
  • POST/decks/{deck_id}/{action}Publish or unpublish one of the app owner's decks
  • GET/decks/{deck_id}/ttsTabletop Simulator manifest v3 (identical to the Deck Import Terminal's; same visibility rules)

Public API · Mechanics, rulings & formats

  • GET/mechanicsSearch approved custom mechanics (plus the app owner's own proposals)
  • GET/mechanics/{mechanic_id}Mechanic definition, reminder text, version, creator, examples, associated cards and rulings
  • GET/mechanics/{mechanic_id}/versionsPrevious versions of a mechanic
  • GET/mechanics/{mechanic_id}/rulingsRulings on a mechanic, ordered by authority
  • GET/rulingsSearch Planar Foundry rulings (foundry, community house rulings, creator explanations)
  • GET/rulings/{ruling_id}A ruling (official orl_… IDs come from Scryfall; rul_… IDs are Planar Foundry rulings)
  • GET/formatsSystem formats, published public custom/community formats and the app owner's formats
  • POST/formatsCreate a custom format owned by the app owner
  • GET/formats/{format_id}A format: rules, banned/restricted lists, supported card types and version
  • PATCH/formats/{format_id}Update a format the app owner manages (bumps its version)
  • GET/formats/{format_id}/versionsVersion history of a format's rules
  • POST/formats/{format_id}/publishPublish a format the app owner manages

Public API · Mechanics & rulings

  • POST/mechanicsPropose a mechanic (enters the same independent review as the website)
  • PATCH/mechanics/{mechanic_id}Revise your mechanic (new version, re-reviewed; the approved version stays public)
  • POST/rulingsAdd a creator explanation or community house ruling, or propose a Foundry ruling
  • POST/rulings/{ruling_id}/withdrawWithdraw a ruling (its author or community staff)
  • GET/rules/queuePending mechanics and rulings for the acting user (Rules Reviewers, or community staff with community_id)
  • POST/rules/{kind}/{item_id}/reviewApprove or reject (two different reviewers for platform items; never your own)

Public API · Communities

  • GET/communitiesApproved public communities, or the app owner's communities with member=me
  • GET/communities/{ref}Community by community_id or slug, with the app owner's role and community permissions
  • PATCH/communities/{ref}Update community metadata (owner/admin community role required)
  • POST/communities/{ref}/joinJoin an open community or request to join (same rules as the website)
  • POST/communities/{ref}/leaveLeave a community (owners must transfer ownership first)
  • GET/communities/{ref}/membersMembers (pending/banned lists need a member-management community role)
  • GET/communities/{ref}/staffCommunity staff roles (owner, admins, moderators, organizers, commissioners)
  • PATCH/communities/{ref}/members/{user_id}Change a member's community role (community owner only)
  • DELETE/communities/{ref}/members/{user_id}Remove a member (member-management community role)
  • POST/communities/{ref}/requests/{user_id}/{decision}Approve or reject a join request
  • GET/communities/{ref}/formatsFormats owned by the community
  • GET/communities/{ref}/collectionsCard libraries and approved card pools
  • GET/collections/{collection_id}A community collection with the cards the app owner may see
  • GET/communities/{ref}/leaguesLeagues of the community
  • GET/communities/{ref}/tournamentsTournaments of the community
  • GET/communities/{ref}/statsCommunity statistics from recorded platform data
  • POST/communities/{ref}/submissionsSubmit one of the app owner's cards to a community
  • GET/communities/{ref}/submissionsSubmissions (reviewers: all; otherwise the app owner's own)
  • GET/submissions/{submission_id}A submission with its review history
  • POST/submissions/{submission_id}/reviewApprove, reject or request changes (community reviewer role required)
  • POST/submissions/{submission_id}/{action}Resubmit (after changes were requested) or withdraw

Public API · Tournaments & leagues

  • POST/communities/{ref}/leaguesCreate a league (app owner must be a league commissioner; enters review)
  • POST/communities/{ref}/tournamentsCreate a tournament (app owner must be a community event organizer)
  • GET/tournamentsPublic tournaments of public communities
  • GET/tournaments/{tid}Tournament details with the app owner's registration and organizer flag
  • PATCH/tournaments/{tid}Organizer: update tournament details
  • GET/tournaments/{tid}/participantsParticipants and waitlist (decklists only when visible)
  • GET/tournaments/{tid}/matchesPairings, brackets (key/bracket/sources) and Commander pods (kind=pod)
  • GET/tournaments/{tid}/standingsLive standings, or final standings once complete
  • GET/tournaments/{tid}/statsTournament statistics from recorded results
  • POST/tournaments/{tid}/{action}Player actions as the app owner: register (deck_id), check-in or withdraw/drop
  • PATCH/tournaments/{tid}/registrationChange the app owner's registered deck while it is not locked
  • POST/tournaments/{tid}/admin/{action}Organizer: open-check-in, start, next-round or cancel
  • PUT/tournaments/{tid}/pending-roundOrganizer: edit proposed pairings (review / manual pairing)
  • POST/tournaments/{tid}/pending-round/publishOrganizer: publish reviewed pairings as matches
  • DELETE/tournaments/{tid}/participants/{user_id}Organizer: remove a registration before the event starts
  • GET/matches/{match_id}A tournament or league match with its result history
  • POST/matches/{match_id}/reportPlayer: report a result (opponents confirm). Duplicate or concurrent reports return 409/400
  • POST/matches/{match_id}/confirmPlayer: confirm the reported result
  • POST/matches/{match_id}/disputePlayer: dispute the reported result
  • POST/matches/{match_id}/resolveOrganizer: settle an open result (final)
  • POST/matches/{match_id}/correctOrganizer: correct a confirmed result (audited)
  • GET/leaguesPublic, approved leagues of public communities
  • GET/leagues/{lid}League with its seasons
  • PATCH/leagues/{lid}Commissioner: update league settings
  • GET/leagues/{lid}/statsLeague statistics from recorded results
  • GET/seasons/{sid}Season: divisions, schedule summary and the app owner's enrollment
  • GET/seasons/{sid}/participantsSeason players (non-active lists need a commissioner role)
  • GET/seasons/{sid}/standingsStandings per division (final once the season is closed)
  • GET/seasons/{sid}/matchesSeason schedule and match results
  • POST/seasons/{sid}/matchesCommissioner: schedule a league match
  • POST/seasons/{sid}/enrollPlayer: enroll in (or apply to) a season as the app owner
  • POST/seasons/{sid}/withdrawPlayer: leave a season
  • POST/seasons/{sid}/logPlayer: log a league match you played (opponents confirm)
  • POST/leagues/{lid}/seasonsCommissioner: add a season with divisions
  • POST/seasons/{sid}/admin/{action}Commissioner: activate or close a season
  • POST/seasons/{sid}/scheduleCommissioner: generate a round robin or pod round for a division
  • POST/seasons/{sid}/participants/{user_id}/{decision}Commissioner: approve, reject, remove or move a player

The Planar Foundry

Forge Your Cards. Build Your Legends. Shape the Multiverse.

A free community workshop for fan-made Magic: The Gathering cards. Official card data and images are provided by Scryfall.

The Planar Foundry is unofficial Fan Content permitted under the Fan Content Policy. Not approved/endorsed by Wizards. Portions of the materials used are property of Wizards of the Coast. ©Wizards of the Coast LLC. Magic: The Gathering, its mana symbols, card names and card images are trademarks of Wizards of the Coast LLC. The Planar Foundry is not affiliated with Wizards of the Coast or Hasbro.