REST API Adding Relationships to Other Tables
REST API Adding Relationships to Other Tables
The endpoints of the REST API specify a particular table from the database that you want to access. Some of those tables are related to other information - tickets are connected to the patrons that bought them, the event that it is for, and the performance time that the patron purchased. You can add in some fo that additional table connections by specifying them.
The starting place is finding what data is related to a particular endpoint using the related feature. The following shows:
- https://127.0.0.1/api/v1/patrons/related - relationships to any patron record
- https://127.0.0.1/api/v1/patrons/51/related - relationships for a specific patron record (#51) which can be followed to see data for that patron.
- https://127.0.0.1/api/v1/marketing/related - relationships for a particular marketing record for the patron so that you can retrieve things like the primary email address, phone, or physical address
Examples are:
- https://127.0.0.1/api/v1/performances?q=perform_datetime:2016-01-01..2016-12-31&include=event
In addition to data from the performance endpoint there is now data from the event endpoint on the end of each row of data. - https://127.0.0.1/api/v1/performances?q=perform_datetime:2017-01-01..2017-12-31&only=event.title+event.show_code+series_code+perform_datetime
Shows event title, show code, series code and performance date/times for performances between 2017-01-01 and 2017-12-31 - https://127.0.0.1/api/v1/performances?q=perform_datetime:>2016-01-01&only=event.title+event.show_code+series_code+perform_datetime+venue.name+venue.address_line_one+venue.city
Shows events title, show code, series code and performance date time for performances after 2016-01-01 and adds the name, address and city of the venue from that relationship - https://127.0.0.1/api/v1/performances.csv?q=perform_datetime:>2016-01-01&only=event.title+event.show_code+series_code+perform_datetime+venue.name+venue.address_line_one+venue.city
Same as above, except in CSV format - https://127.0.0.1/api/v1/performances.json?q=perform_datetime:>2016-01-01&only=event.title+event.show_code+series_code+perform_datetime+venue.name+venue.address_line_one+venue.city
Same as above, except in JSON format - https://127.0.0.1/api/v1/marketing?only=patron.first_name+patron.last_name+patron.company+primary_email.contents+primary_address.address_line_one+primary_address.city
Show patron names and the primary address and email.
REST API - showing relationships
REST API - showing relationships
If you just wish to show the other tales that are related to a specific table, you can show an endpoint (like orders or carts or patrons) and add /related to the url. eg:
https://127.0.0.1/api/v1/orders/related
Other Examples:
- https://127.0.0.1/api/v1/orders/related
Relationships for orders - https://127.0.0.1/api/v1/patrons/related
Relationships for patrons - https://127.0.0.1/api/v1/carts/related
Relationships for all cart related items - https://127.0.0.1/api/v1/orders/related?group=type+refers_to&agg=count&sort=-type
Count of other tables that refer to orders by adding aggregate, sort and grouping functions