# OpenAPI spec of the public Hipsy API v1, served at https://docs.hipsy.nl/openapi.yaml.
# Mirrors apps/web (routes/api.php, ApiController, app/Http/Resources). When the API changes, update this file and the
# Markdown page in src/pages/api-reference: tests/Feature/api/ApiV1OpenApiTest.php in apps/web fails otherwise.
openapi: 3.1.0
info:
  title: Hipsy API
  version: 1.0.0
  summary: Read the events, orders and reviews of your Hipsy organisations.
  description: |
    The public API of [Hipsy](https://hipsy.nl), the ticketing platform for event organisers. All endpoints are
    read-only `GET` requests that return JSON.

    Authenticate with an [API key](https://docs.hipsy.nl/the-api-key) for your own account, or with an
    [OAuth 2.0](https://docs.hipsy.nl/oauth) access token when you build an app that other Hipsy users connect to.
    Both go in the `Authorization: Bearer {token}` header.

    Always send `Accept: application/json`. Without it, a missing or invalid token redirects to the login page
    (`302`) instead of returning `401`.

    Requests are limited to 120 per minute per user, shared by all keys and tokens of that user. Dates are ISO 8601
    in UTC, money is in euros.
  contact:
    name: Hipsy
    email: info@hipsy.nl
    url: https://docs.hipsy.nl
servers:
  - url: https://api.hipsy.nl/v1
security:
  - apiKey: []
  - oauth2: []
tags:
  - name: Account
    description: The user and its organisations.
  - name: Events
    description: Events of an organisation and their tickets.
  - name: Orders
    description: Paid orders of an organisation.
  - name: Reviews
    description: Reviews of an organisation.

paths:
  /me:
    get:
      operationId: getCurrentAccount
      summary: Current account
      description: The Hipsy user the API key or access token belongs to.
      tags: [Account]
      security:
        - apiKey: []
        - oauth2: ['profile:read']
      responses:
        '200':
          description: The user.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Account'
              example:
                id: 1234
                name: Jane Doe
                email: jane@example.com
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /organisations/index:
    get:
      operationId: listOrganisations
      summary: List organisations
      description: |
        All organisations the user is a member of. Not paginated.

        With OAuth this lists all organisations of the user, also the ones the user did not grant to your app.
      tags: [Account]
      security:
        - apiKey: []
        - oauth2: ['organisations:read']
      responses:
        '200':
          description: The organisations.
          content:
            application/json:
              schema:
                type: object
                required: [data]
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Organisation'
              example:
                data:
                  - id: 1000
                    name: My organisation
                    slug: my-organisation
                    logo: https://cdn.hipsy.nl/images/organisations/1000ItXCGss6.png
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /organisation/{organisation}/events:
    get:
      operationId: listEvents
      summary: List events
      description: |
        The events of the organisation, including events it co-organises. Concept (draft) and private events are
        left out unless you ask for them.

        `upcoming` events are sorted from soonest to latest. `past` and `all` are sorted from most recent to oldest.
      tags: [Events]
      security:
        - apiKey: []
        - oauth2: ['organisation.events:read']
      parameters:
        - $ref: '#/components/parameters/Organisation'
        - name: period
          in: query
          description: |
            `upcoming`: events that start from one hour ago. `past`: events that ended more than one hour ago.
            `all`: all events. Any other value lists all events. Ignored when `id` is given.
          schema:
            type: string
            enum: [upcoming, past, all]
            default: upcoming
        - name: id
          in: query
          description: Return only this event. Still left out when it is private and `private` is not set.
          schema:
            type: integer
        - name: concepts
          in: query
          description: Include concept events. Any value turns it on, except `0` and `false`.
          schema:
            type: string
          allowEmptyValue: true
          example: '1'
        - name: private
          in: query
          description: Include private events with `1` or `true`.
          schema:
            type: string
            enum: ['0', '1', 'true', 'false']
            default: '0'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Page'
      responses:
        '200':
          description: A page of events.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Paginated'
                  - type: object
                    required: [data]
                    properties:
                      data:
                        type: array
                        items:
                          $ref: '#/components/schemas/Event'
              example:
                data:
                  - id: 1032
                    title: Ecstatic Dance Universe - Kareem
                    description: "Description of the event\n\nAll the info of the event"
                    location: Amersfoort, Nederland
                    latitude: 52.1561113
                    longitude: 5.3878266
                    picture: https://cdn.hipsy.nl/images/events/pic1.jpg
                    picture_small: https://cdn.hipsy.nl/images/events/pic1.jpg
                    date: '2023-03-01T19:00:00.000000Z'
                    date_until: '2023-03-01T22:00:00.000000Z'
                    sold_out: false
                    private: false
                    disable_tickets: false
                    url_hipsy: https://hipsy.nl/event/1032-ecstatic-dance-universe-kareem
                    url_ticketshop: https://hipsy.nl/shop/1032-ecstatic-dance-universe-kareem
                    qr_ticketshop: https://hipsy.nl/qr/ticketshop-1032.png
                    tickets:
                      - id: 83
                        type: ticket
                        name: Early Bird
                        description: ''
                        price: 17.5
                        is_entry_ticket: true
                        status: sale
                        available: 7
                        sale_start: '2023-01-22T10:00:00.000000Z'
                        sale_end: null
                    organisation:
                      id: 1000
                      name: Ecstatic Dance Universe
                      slug: ecstatic-dance-universe
                      logo: https://cdn.hipsy.nl/images/organisations/1000ItXCGss6.png
                    categories: [Ecstatic Dance]
                links:
                  first: https://api.hipsy.nl/v1/organisation/ecstatic-dance-universe/events?page=1
                  last: https://api.hipsy.nl/v1/organisation/ecstatic-dance-universe/events?page=1
                  prev: null
                  next: null
                meta:
                  current_page: 1
                  from: 1
                  last_page: 1
                  links: []
                  path: https://api.hipsy.nl/v1/organisation/ecstatic-dance-universe/events
                  per_page: 25
                  to: 1
                  total: 1
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /organisation/{organisation}/orders:
    get:
      operationId: listOrders
      summary: List orders
      description: The paid orders of the organisation, newest first. Each order lists its tickets, cancelled ones included.
      tags: [Orders]
      security:
        - apiKey: []
        - oauth2: ['organisation.orders:read']
      parameters:
        - $ref: '#/components/parameters/Organisation'
        - name: event
          in: query
          description: Only orders of this event, or of several events as a comma-separated list of IDs.
          schema:
            type: string
          example: '1030,1032'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Page'
      responses:
        '200':
          description: A page of orders.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Paginated'
                  - type: object
                    required: [data]
                    properties:
                      data:
                        type: array
                        items:
                          $ref: '#/components/schemas/Order'
              example:
                data:
                  - id: 1148
                    event_id: 1030
                    event_name: Ecstatic Dance Universe - Kareem
                    revenue: 17.5
                    first_name: Jane
                    last_name: Doe
                    email: jane@example.com
                    locale: nl
                    newsletter: false
                    date: '2022-12-16T15:04:51.000000Z'
                    personal_data:
                      city: Utrecht
                      phone: null
                      gender: null
                      address: null
                      comment: null
                      company: null
                      dietary: null
                      birthday: null
                      postcode: null
                      question1: null
                      question2: null
                      question3: null
                    utm:
                      utm_source: newsletter
                      utm_medium: email
                      utm_campaign: null
                      utm_term: null
                      utm_content: null
                    tickets:
                      - number: 114857291
                        event_ticket_id: 83
                        event_ticket_name: Early Bird
                        checkin: false
                        price_ticket: '17.50'
                        price_final: '18.45'
                links:
                  first: https://api.hipsy.nl/v1/organisation/ecstatic-dance-universe/orders?page=1
                  last: https://api.hipsy.nl/v1/organisation/ecstatic-dance-universe/orders?page=1
                  prev: null
                  next: null
                meta:
                  current_page: 1
                  from: 1
                  last_page: 1
                  links: []
                  path: https://api.hipsy.nl/v1/organisation/ecstatic-dance-universe/orders
                  per_page: 25
                  to: 1
                  total: 1
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /organisation/{organisation}/reviews:
    get:
      operationId: listReviews
      summary: List reviews
      description: |
        The reviews of the organisation, newest first. Always 15 per page: `limit` is not supported.

        Unlike the other lists, `links` holds relative query strings (`?page=2`) and `meta.path` is empty.
      tags: [Reviews]
      security:
        - apiKey: []
        - oauth2: ['organisation.reviews:read']
      parameters:
        - $ref: '#/components/parameters/Organisation'
        - $ref: '#/components/parameters/Page'
      responses:
        '200':
          description: A page of reviews.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Paginated'
                  - type: object
                    required: [data]
                    properties:
                      data:
                        type: array
                        items:
                          $ref: '#/components/schemas/Review'
              example:
                data:
                  - id: 512
                    reviewer:
                      id: 4821
                      name: Jane
                      avatar_url: null
                    event: Ecstatic Dance Universe - Kareem
                    text: What a beautiful evening, great music and a lovely atmosphere!
                    rating: 5
                    reply: Thank you Jane, see you next time!
                    replied_at: '2023-03-03T09:12:44.000000Z'
                    created_at: '2023-03-02T18:30:10.000000Z'
                links:
                  first: '?page=1'
                  last: '?page=1'
                  prev: null
                  next: null
                meta:
                  current_page: 1
                  from: 1
                  last_page: 1
                  links: []
                  path: ''
                  per_page: 15
                  to: 1
                  total: 1
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: |
        A personal API key, created in the Hipsy dashboard under 'Koppelingen'. It belongs to a user, never expires
        and gives access to all organisations of that user. Scopes do not apply to API keys.
    oauth2:
      type: oauth2
      description: |
        For apps that other Hipsy users connect to. Organisation scopes are granted per organisation by the user.
        Access tokens are valid for one hour; refresh tokens rotate on use.
      flows:
        authorizationCode:
          authorizationUrl: https://hipsy.nl/oauth/authorize
          tokenUrl: https://hipsy.nl/oauth/token
          refreshUrl: https://hipsy.nl/oauth/token
          scopes:
            'profile:read': Read the name and email of the user. Always granted.
            'organisations:read': List the organisations of the user.
            'organisation.events:read': Read the events of a granted organisation.
            'organisation.orders:read': Read the orders of a granted organisation.
            'organisation.reviews:read': Read the reviews of a granted organisation.

  parameters:
    Organisation:
      name: organisation
      in: path
      required: true
      description: |
        The ID or the slug of the organisation. Prefer the ID: the slug changes when the organisation changes it.
      schema:
        type: string
      example: '1000'
    Limit:
      name: limit
      in: query
      description: Items per page, at most 100. Values below 1 use the default and values above 100 return 100.
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 25
    Page:
      name: page
      in: query
      schema:
        type: integer
        minimum: 1
        default: 1

  responses:
    Unauthenticated:
      description: 'The token is missing, invalid, expired or revoked. Only returned with `Accept: application/json`.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            message: Unauthenticated.
    Forbidden:
      description: |
        The user is not a member of the organisation, or (OAuth) the token misses the scope or the organisation was
        not granted to your app.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            noAccess:
              value:
                message: This action is unauthorized.
            missingScope:
              value:
                message: Invalid scope(s) provided.
    NotFound:
      description: The organisation does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            message: Organisation not found.
    TooManyRequests:
      description: More than 120 requests in a minute.
      headers:
        Retry-After:
          description: Seconds until you can send requests again.
          schema:
            type: integer
        X-RateLimit-Limit:
          schema:
            type: integer
        X-RateLimit-Remaining:
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            message: Too Many Attempts.

  schemas:
    Error:
      type: object
      required: [message]
      properties:
        message:
          type: string

    Account:
      type: object
      required: [id, name, email]
      properties:
        id:
          type: integer
        name:
          type: string
          description: Full name of the user.
        email:
          type: string
          format: email

    Organisation:
      type: object
      required: [id, name, slug, logo]
      properties:
        id:
          type: integer
        name:
          type: string
        slug:
          type: string
        logo:
          type: string
          description: URL of the logo.

    Event:
      type: object
      required:
        - id
        - title
        - description
        - location
        - latitude
        - longitude
        - picture
        - picture_small
        - date
        - date_until
        - sold_out
        - private
        - disable_tickets
        - url_hipsy
        - url_ticketshop
        - qr_ticketshop
        - tickets
        - organisation
        - categories
      properties:
        id:
          type: integer
        title:
          type: string
        description:
          type: [string, 'null']
        location:
          type: [string, 'null']
        latitude:
          type: number
        longitude:
          type: number
        picture:
          type: string
          description: URL of the event picture. Empty string when the event has no picture.
        picture_small:
          type: string
          description: Currently the same as `picture`.
        date:
          type: string
          format: date-time
          description: Start of the event.
        date_until:
          type: [string, 'null']
          format: date-time
          description: End of the event.
        sold_out:
          type: boolean
        private:
          type: boolean
          description: Only reachable with a direct link.
        disable_tickets:
          type: boolean
          description: Ticket sales via Hipsy are turned off.
        url_hipsy:
          type: string
          description: The event page on hipsy.nl.
        url_ticketshop:
          type: string
          description: The ticket shop of the event.
        qr_ticketshop:
          type: string
          description: URL of a QR code image that links to the ticket shop.
        tickets:
          type: array
          items:
            $ref: '#/components/schemas/EventTicket'
        organisation:
          $ref: '#/components/schemas/Organisation'
          description: The organisation that owns the event. For a co-organised event this is the other organisation.
        categories:
          type: array
          description: Names of the event categories.
          items:
            type: string

    EventTicket:
      type: object
      description: A ticket type of an event.
      required: [id, type, name, description, price, is_entry_ticket, status, available, sale_start, sale_end]
      properties:
        id:
          type: integer
        type:
          type: string
          enum: [ticket, donation, combiticket, product]
        name:
          type: string
        description:
          type: [string, 'null']
        price:
          type: number
          description: Price the buyer pays per ticket in euros, service fee included. `0` for free and donation tickets.
        is_entry_ticket:
          type: boolean
        status:
          type: string
          enum: [sale, sold, invisible, not_available, start_future]
        available:
          type: integer
          description: Tickets left. `99999` means unlimited.
        sale_start:
          type: [string, 'null']
          format: date-time
        sale_end:
          type: [string, 'null']
          format: date-time
        url:
          type: string
          description: Direct link to buy this ticket. Only present when `status` is `invisible`.

    Order:
      type: object
      required:
        - id
        - event_id
        - event_name
        - revenue
        - first_name
        - last_name
        - email
        - locale
        - newsletter
        - date
        - personal_data
        - utm
        - tickets
      properties:
        id:
          type: integer
        event_id:
          type: integer
        event_name:
          type: string
        revenue:
          type: number
          description: Revenue of the order in euros, service fees excluded.
        first_name:
          type: [string, 'null']
        last_name:
          type: [string, 'null']
        email:
          type: string
        locale:
          type: string
          enum: [nl, en, de, fr, es]
        newsletter:
          type: boolean
          description: The buyer signed up for the newsletter of the organisation.
        date:
          type: string
          format: date-time
        personal_data:
          $ref: '#/components/schemas/PersonalData'
        utm:
          $ref: '#/components/schemas/Utm'
        tickets:
          type: array
          description: Tickets of the order, cancelled ones included.
          items:
            $ref: '#/components/schemas/OrderTicket'

    PersonalData:
      type: object
      description: Answers to the order form. Every key is always present, `null` when not asked or not answered.
      required: [city, phone, gender, address, comment, company, dietary, birthday, postcode, question1, question2, question3]
      properties:
        city: { type: [string, 'null'] }
        phone: { type: [string, 'null'] }
        gender: { type: [string, 'null'] }
        address: { type: [string, 'null'] }
        comment: { type: [string, 'null'] }
        company: { type: [string, 'null'] }
        dietary: { type: [string, 'null'] }
        birthday: { type: [string, 'null'] }
        postcode: { type: [string, 'null'] }
        question1: { type: [string, 'null'] }
        question2: { type: [string, 'null'] }
        question3: { type: [string, 'null'] }

    Utm:
      type: object
      description: UTM parameters of the visit that led to the order. Every key is always present.
      required: [utm_source, utm_medium, utm_campaign, utm_term, utm_content]
      properties:
        utm_source: { type: [string, 'null'] }
        utm_medium: { type: [string, 'null'] }
        utm_campaign: { type: [string, 'null'] }
        utm_term: { type: [string, 'null'] }
        utm_content: { type: [string, 'null'] }

    OrderTicket:
      type: object
      required: [number, event_ticket_id, event_ticket_name, checkin, price_ticket, price_final]
      properties:
        number:
          type: integer
          description: The ticket number, also in the QR code.
        event_ticket_id:
          type: integer
          description: ID of the ticket type (`tickets[].id` of the event).
        event_ticket_name:
          type: string
        checkin:
          type: boolean
          description: The ticket was scanned at the entrance.
        price_ticket:
          type: string
          description: Ticket price in euros as a string with two decimals.
          example: '17.50'
        price_final:
          type: string
          description: Price the buyer paid in euros as a string with two decimals, service fee included.
          example: '18.45'

    Review:
      type: object
      required: [id, reviewer, event, text, rating, reply, replied_at, created_at]
      properties:
        id:
          type: integer
        reviewer:
          $ref: '#/components/schemas/Reviewer'
        event:
          type: string
          description: Name of the event the review is about.
        text:
          type: [string, 'null']
        rating:
          type: integer
          minimum: 1
          maximum: 5
        reply:
          type: [string, 'null']
          description: Reply of the organisation.
        replied_at:
          type: [string, 'null']
          format: date-time
        created_at:
          type: string
          format: date-time

    Reviewer:
      type: object
      required: [id, name, avatar_url]
      properties:
        id:
          type: [integer, 'null']
        name:
          type: string
          description: The name the reviewer chose to show, for example the full name, first name, initials or a localized "Anonymous".
        avatar_url:
          type: 'null'
          description: Always `null`.

    Paginated:
      type: object
      required: [links, meta]
      properties:
        links:
          type: object
          required: [first, last, prev, next]
          properties:
            first: { type: [string, 'null'] }
            last: { type: [string, 'null'] }
            prev: { type: [string, 'null'] }
            next: { type: [string, 'null'] }
        meta:
          type: object
          required: [current_page, from, last_page, links, path, per_page, to, total]
          properties:
            current_page:
              type: integer
            from:
              type: [integer, 'null']
            last_page:
              type: integer
            links:
              type: array
              items:
                type: object
                required: [url, label, active]
                properties:
                  url: { type: [string, 'null'] }
                  label: { type: string }
                  page: { type: [integer, 'null'] }
                  active: { type: boolean }
            path:
              type: [string, 'null']
            per_page:
              type: integer
            to:
              type: [integer, 'null']
            total:
              type: integer
