Sync paginated contract details via API
API toolWorkatoRecipe ToolsDeveloper ToolMarketingDatabase
What it does
When someone makes an API request, this automation retrieves contract data from SQL Server in pages. It returns the requested page of results with a total count so the caller knows how many records exist.
Who it's for
Engineering teams who need paginated contract data from SQL Server through an API endpoint.
How teams use this
Load contracts in a web interface
A web app calls this API to display contracts in a table with pagination controls. The total count lets the interface show how many pages exist, and each request fetches only the rows needed for that page.
Filter contracts by status before paginating
Modify the SQL queries to add a condition that filters contracts by status before pagination runs. The page logic stays the same and only the data set changes.
Add contract metadata to each row
Include additional fields like contract owner or renewal date in the query so each returned contract row contains more details. Set the response schema to match the new fields.
How it works
- Receive the API request. Define request parameters like page number and page size, and set up the response structure to return contract rows and a total count.
- Prepare the query parameters. Execute Ruby code to format the page number and size into SQL Server parameters so the query runs with the right offset and limit.
- Count total contracts. Run a SQL query in SQL Server to get the total number of contracts that match the filter, regardless of pagination.
- Fetch the current page. Run a SQL query in SQL Server to retrieve only the contract rows for the requested page based on the offset and limit.
- Build and return the response. Execute Ruby code to format the page of contracts and total count into the API response, then return it to the caller.