{
  "openapi": "3.1.0",
  "info": {
    "title": "Friendly Payroll API",
    "version": "1",
    "description": "Embed payroll in your product. Your server creates Sessions with this API, and your frontend renders them with `<friendly-payroll>`."
  },
  "servers": [
    {
      "url": "https://api.friendlypayroll.com",
      "description": "Prod (`sk_prod_…` keys)"
    },
    {
      "url": "https://api.sandbox.friendlypayroll.com",
      "description": "Sandbox (`sk_sandbox_…` keys)"
    }
  ],
  "components": {
    "securitySchemes": {
      "SecretKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your secret key: `sk_sandbox_…` in Sandbox or `sk_prod_…` in Prod. Use it only on your server."
      }
    },
    "schemas": {
      "Session": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "jn7exampleexampleexampleexample00"
          },
          "object": {
            "type": "string",
            "enum": [
              "session"
            ]
          },
          "audience": {
            "type": "string",
            "enum": [
              "employer",
              "worker"
            ],
            "description": "`employer` when someone at the Employer is viewing; `worker` when the Worker is."
          },
          "screens": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ScreenName"
            }
          },
          "clientSecret": {
            "type": "string",
            "description": "Pass this to `<friendly-payroll>` in the browser. Treat it like a password: it grants access until `expiresAt`.",
            "example": "fpcs_sandbox_EXAMPLEonlyNotARealSecret0000000000000000000000000"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-11-20T12:46:24.218Z"
          }
        },
        "required": [
          "id",
          "object",
          "audience",
          "screens",
          "clientSecret",
          "expiresAt"
        ]
      },
      "ScreenName": {
        "type": "string",
        "enum": [
          "employer-dashboard",
          "employer-onboarding",
          "employer-onboard-workers",
          "payroll-run-list",
          "run-payroll",
          "employer-setup-personalization",
          "employer-taxes-setup",
          "employer-sign-documents",
          "employer-pay-groups",
          "employer-address-list",
          "employer-bank-accounts",
          "employer-profile",
          "employer-documents",
          "employer-reports",
          "worker-profile",
          "onboard-worker",
          "worker-onboarding",
          "worker-self-managed-profile",
          "worker-payment-list",
          "worker-documents"
        ],
        "description": "A piece of payroll UI you can embed. Employer Screens and Worker Screens cannot be mixed in one Session."
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "authentication_error"
                ]
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "type",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ],
        "description": "Every non-2xx response has this shape."
      },
      "CreateSessionRequest": {
        "type": "object",
        "properties": {
          "screens": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ScreenName"
            },
            "minItems": 1,
            "description": "Every Screen this Session may show. The client secret can’t be used for any other Screen.",
            "example": [
              "employer-dashboard",
              "payroll-run-list"
            ]
          },
          "employer": {
            "$ref": "#/components/schemas/EmployerInput"
          },
          "worker": {
            "$ref": "#/components/schemas/WorkerInput"
          },
          "theme": {
            "$ref": "#/components/schemas/Theme"
          }
        },
        "required": [
          "screens",
          "employer"
        ],
        "additionalProperties": false
      },
      "EmployerInput": {
        "type": "object",
        "properties": {
          "externalId": {
            "type": "string",
            "minLength": 1,
            "description": "Your ID for this Employer. Unique within your account.",
            "example": "acct_8812"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "description": "Business name. Required the first time you use an `externalId`, then ignored.",
            "example": "Acme Plumbing LLC"
          }
        },
        "required": [
          "externalId"
        ],
        "additionalProperties": false
      },
      "WorkerInput": {
        "type": "object",
        "properties": {
          "externalId": {
            "type": "string",
            "minLength": 1,
            "description": "Your ID for this Worker. Unique within the Employer.",
            "example": "user_51"
          },
          "firstName": {
            "type": "string",
            "minLength": 1,
            "example": "Ada"
          },
          "lastName": {
            "type": "string",
            "minLength": 1,
            "example": "Lovelace"
          },
          "displayName": {
            "type": "string",
            "minLength": 1,
            "description": "Required the first time you use an `externalId`, unless you give both `firstName` and `lastName`."
          },
          "email": {
            "type": "string",
            "format": "email"
          }
        },
        "required": [
          "externalId"
        ],
        "additionalProperties": false,
        "description": "Required for Worker Screens (the Worker is viewing) and for Employer Screens about one Worker (`worker-profile`, `onboard-worker`). Omit it otherwise."
      },
      "Theme": {
        "type": "object",
        "properties": {
          "colorMode": {
            "type": "string",
            "enum": [
              "light",
              "dark",
              "system"
            ],
            "description": "Follow light or dark mode, or the viewer’s system setting."
          },
          "primaryColor": {
            "type": "string",
            "description": "Brand color as a CSS color. Applied only together with `secondaryColor`.",
            "example": "#1f3d2b"
          },
          "secondaryColor": {
            "type": "string",
            "description": "Secondary brand color. Applied only together with `primaryColor`.",
            "example": "#f4f1ea"
          }
        },
        "additionalProperties": false,
        "description": "How Embeds look. Values here override your dashboard default for this Session only."
      }
    },
    "parameters": {}
  },
  "paths": {
    "/v1/sessions": {
      "post": {
        "operationId": "createSession",
        "tags": [
          "Sessions"
        ],
        "summary": "Create a Session",
        "description": "Creates a short-lived Session that lets one person view the given Screens. Call this from your server,\nthen pass the `clientSecret` to `<friendly-payroll>` in the browser.\n\nThe first time you use an Employer or Worker `externalId`, Friendly Payroll creates it, so include its\nname. After that, the `externalId` alone is enough.",
        "security": [
          {
            "SecretKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSessionRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The Session was created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says why.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The secret key is missing, invalid, or for the other mode.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {}
}