I have a scheduling app, and the user needs to be able to set days of the week in which a bus route will be created automatically for the net year. The route includes a list of stops, whose time also needs to be changed to fit the new dates.
I am using this plugin Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
To get the list of dates on selected days. EG 52 dates for each monday in the next year.
My problem is: I have a list of dates the plugin spits out. Now I need to create new routes (I think using an api workflow) and then for each of those new routes to be assigned each of the dates. So if user elects monday then it will copy the route 52 times (for each Monday in the coming year) and then the monday dates (list given through the plugin) will be updated for each of the 52 routes.
Please note that each time a route gets created, I also need to copy and paste a lsit of stops associated with that route.
So I need:
- Copy and paste a new route and lsit of stops 52 times
- use the plugins list of dates to assign each date to each new route
Thanks in advance for any help
Sure, let’s break down what the API workflow will look like in Bubble.io. Here’s a step-by-step guide to setting up the API workflow:
Step 1: Create the API Workflow for Creating Routes and Stops
-
Go to Backend Workflows:
- Navigate to the “Backend Workflows” tab in your Bubble.io editor.
-
Create API Workflow create_route_and_stops:
- Click on “Add a new API endpoint”.
- Name it
create_route_and_stops.
- Add parameters:
date (type: Date)
original_route_id (type: Route)
-
Add Actions to Create Route and Stops:
- Create a New Route:
- Action: “Create a new thing”
- Type:
Route
- Fields:
date: This Workflow's date
- Any other fields you need to set for the route.
- Copy Stops:
- Add a workflow to “Create a new thing” for each stop associated with the
original_route_id.
- You may need to use “Do a Search for” to find the stops related to the
original_route_id.
- Action: “Create a new thing”
- Type:
Stop
- Fields:
time: Set according to the new date and the time of the original stop.
location: Copy from the original stop.
- Associate the stop with the new route.
Step 2: Create Recursive Scheduling API Workflow
-
Create API Workflow schedule_next_route:
- Click on “Add a new API endpoint”.
- Name it
schedule_next_route.
- Add parameters:
dates_list (type: List of Dates)
original_route_id (type: Route)
current_index (type: Number)
-
Add Actions to Schedule the Route Creation and Next Event:
Example Implementation
API Workflow create_route_and_stops
-
Parameters:
date (Date)
original_route_id (Route)
-
Actions:
-
Create New Route:
- Action: “Create a new thing”
- Type:
Route
- Fields:
date: date
- Other fields as required.
-
Create Stops:
- Action: “Create a new thing” (repeat for each stop in the original route)
- Type:
Stop
- Fields:
time: Calculate based on date and original stop time.
location: Copy from the original stop.
- Link to the newly created route.
API Workflow schedule_next_route
-
Parameters:
dates_list (List of Dates)
original_route_id (Route)
current_index (Number)
-
Actions:
-
Schedule create_route_and_stops Workflow:
- Action: “Schedule API Workflow”
- Workflow:
create_route_and_stops
- Schedule date/time: Current date/time
- Parameters:
date: dates_list:item #current_index
original_route_id: original_route_id
-
Schedule Next schedule_next_route (if more dates left):
- Action: “Schedule API Workflow”
- Workflow:
schedule_next_route
- Only when:
current_index < dates_list:count
- Schedule date/time: Current date/time + 1 second
- Parameters:
dates_list: dates_list
original_route_id: original_route_id
current_index: current_index + 1
Triggering the Recursive Scheduling
-
Generate Dates and Store:
- Use the plugin to generate the list of dates and store it in a custom state or a list in the database.
-
Start Recursive Scheduling:
- Create a workflow triggered by a user action (e.g., button click).
- Add an action to schedule the
schedule_next_route API Workflow with the initial parameters:
dates_list: List of dates generated by the plugin.
original_route_id: ID of the original route to copy stops from.
current_index: 1 (starting index).
Example Bubble Workflow Steps:
-
Generate Dates and Store:
When Button "Generate Dates" is clicked:
- Generate Dates using Plugin
- Set State or Create a new Thing to store the dates list
-
Trigger Recursive Scheduling:
When Button "Schedule Routes" is clicked:
- Schedule API Workflow `schedule_next_route`:
- dates_list: State or Thing storing the list of dates
- original_route_id: ID of the original route
- current_index: 1
By following these steps, you will be able to recursively schedule the creation of routes and stops for each date using Bubble.io’s API workflows.