OpenActive Developers
Data ValidatorDataset DashboardW3C Community Group
  • Welcome to our community
  • Publishing Data
    • Data Feeds
      • How an RPDE data feed works
      • Types of RDPE feed
      • Implementing RPDE
      • Testing RPDE feeds
      • Scaling RPDE feeds
    • Activity list references
    • Including geo coordinates
    • Schedules
    • Dataset Sites
    • Virtual Events
    • On-Demand Events
    • Opening Hours
    • Data Quality
  • Using data
    • Harvesting opportunity data
      • Large Integers in JavaScript
    • Tutorial: Consuming an RPDE feed
    • Attribution
  • Open Booking API
    • Key Decisions
    • Implementing booking
    • Testing booking
      • Configuring Test Suite
      • Implementing the Test Interface
        • Test Interface Actions
        • Create Opportunity Endpoint
      • Random Mode: Generating Test Opportunity Data
      • Running Test Suite
      • Generating the Conformance Certificate
  • Data Model
    • Data Model Overview
    • @context and JSON-LD
    • Types Reference
      • Action
      • AudioObject
      • BabyChanging
      • Barcode
      • BookingService
      • BooleanFormFieldSpecification
      • Brand
      • ChangingFacilities
      • ConceptScheme
      • Concept
      • CourseInstance
      • Course
      • Creche
      • CustomerAccount
      • DataCatalog
      • DataDownload
      • Dataset
      • DropdownFormFieldSpecification
      • DynamicPayment
      • Entitlement
      • EventSeries
      • Event
      • FacilityUse
      • FileUploadFormFieldSpecification
      • GeoCoordinates
      • HeadlineEvent
      • ImageObject
      • IndividualFacilityUse
      • InternalApplicationError
      • InternalLibraryConfigurationError
      • InternalLibraryError
      • Lease
      • LocationFeatureSpecification
      • Lockers
      • MediaObject
      • OfferOverride
      • Offer
      • OnDemandEvent
      • OpenBookingError
      • OpeningHoursSpecification
      • OrderItem
      • OrderProposal
      • OrderQuote
      • Order
      • Organization
      • ParagraphFormFieldSpecification
      • Parking
      • PartialSchedule
      • Payment
      • Person
      • Place
      • PostalAddress
      • PriceSpecification
      • PrivacyPolicy
      • PropertyValueSpecification
      • PropertyValue
      • QuantitativeValue
      • Schedule
      • ScheduledSession
      • SessionSeries
      • ShortAnswerFormFieldSpecification
      • Showers
      • Slot
      • SportsActivityLocation
      • TaxChargeSpecification
      • TermsOfUse
      • Terms
      • Toilets
      • Towels
      • VideoObject
      • VirtualLocation
      • WebAPI
  • Specifications
    • Specifications Overview
  • Useful links
    • Data Visualiser
    • Data Validator
    • Dataset Dashboard
    • Non-technical Guidance
  • OpenActive on GitHub
    • Overview
    • Activity List
    • Community
    • Controlled Vocabularies
    • Dataset Publication
    • Documentation
    • Implementation Support
    • Programmes
    • RPDE
    • SKOS
    • Specifications
    • Validators
Powered by GitBook
On this page
  • Which Criteria to implement?
  • Create Opportunity Endpoint Implementation Guidelines
  • 1. Switch Statement
Edit on GitHub
  1. Open Booking API
  2. Testing booking
  3. Implementing the Test Interface

Create Opportunity Endpoint

PreviousTest Interface ActionsNextRandom Mode: Generating Test Opportunity Data

Last updated 1 year ago

The Create Opportunity endpoint (POST /test-interface/datasets/:testDatasetIdentifier/opportunities) is part of the Test Interface (see the full detail in its ). It is called by to create test in your booking system.

This doc contains some guidance for how and what to implement for this endpoint.

The payload for this endpoint includes a field, test:testOpportunityCriteria, which defines what type of Opportunity should be created. For example, if this is set to https://openactive.io/test-interface#TestOpportunityBookableFree, then the created opportunity must be both and cost no money to book.

The full list of Opportunity Criteria, and what is expected for each, can be found in the — it's every row with Type = test:TestOpportunityCriteriaEnumeration.

Your booking system only needs to implement, for this endpoint, those criteria which relate to that it implements. For example, if your booking system doesn't support free bookings, it does not need to support any of the free opportunity criteria.

Which Criteria to implement?

Use to find out which criteria your booking system needs to implement. Follow these steps:

  1. In your Test Suite instance, , run:

# Use your config/dev.json config file
export NODE_ENV=dev
# Run Test Data Generator
npm run test-data-generator
  1. The logs from this script will point to two files that it generated, called:

    • opportunity-test-data.json

    • test-interface-actions.json

  2. The opportunity-test-data.json file will contain a list of Opportunity Criteria that you need to implement for the features that your booking system supports. To see an example of what this looks like, see the .

Create Opportunity Endpoint Implementation Guidelines

1. Switch Statement

Use something like a switch statement for this endpoint.

app.post('/test-interface/datasets/:testDatasetIdentifier/opportunities', (req, res) => {
  const opportunityType = req.body['@type'];
  const criteria = req.body['test:testOpportunityCriteria'];
  switch (opportunityType) {
    case 'ScheduledSession':
      switch (criteria) {
        case 'https://openactive.io/test-interface#TestOpportunityBookable':
          createTestOpportunityBookableScheduledSession(req, res);
          break;
        case 'https://openactive.io/test-interface#TestOpportunityBookableCancellable':
          createTestOpportunityBookableCancellableScheduledSession(req, res);
          break;
        default:
          res.sendStatus(404);
          break;
      }
      break;
    case 'Slot': {
      const facilityUseType = req.body.facilityUse['@type'];
      switch (facilityUseType) {
        case 'IndividualFacilityUse':
          switch (criteria) {
            case 'https://openactive.io/test-interface#TestOpportunityBookable':
              createTestOpportunityBookableIfuSlot(req, res);
              break;
            case 'https://openactive.io/test-interface#TestOpportunityBookableCancellable':
              createTestOpportunityBookableCancellableIfuSlot(req, res);
              break;
            default:
              res.sendStatus(404);
              break;
          }
          break;
        default:
          res.sendStatus(404);
          break;
      }
    }
    default:
      res.sendStatus(404);
      break;
  }
});

For example, if your booking system only needs to support the https://openactive.io/test-interface#TestOpportunityBookable and https://openactive.io/test-interface#TestOpportunityBookableCancellable criteria — and only supports , your route would look like (using Node.js with Express as an example):

There is an example of this in the code base for , which is an example implementation of a booking system in .NET. That example is .

specification
Test Suite
opportunities
bookable
Enumeration Values table in the Test Interface doc
features
Test Data Generator
which you configured in the previous step
Test Data Generator README
ScheduledSessions and IndividualFacilityUseSlots
BookingSystem.AspNetCore
here