Sync contacts from SQL Server via Odata API

Recipe ToolsDatabaseMarketing

What it does

When someone calls the Odata API endpoint, this automation retrieves contacts from SQL Server and returns them as a response. Query parameters like orderby, top, skip, and filter are parsed and applied to shape the result.

Who it's for

Data and analytics teams who need to expose SQL Server contacts through an API without building custom code.

How teams use this

Retrieve sorted contacts from the API

Call the endpoint with orderby=email to get contacts sorted by email address. The automation parses the parameter and applies ORDER BY to the SQL query before returning results.

Paginate large contact lists

Use top=50 and skip=100 parameters to fetch the third page of 50 contacts. The automation converts these into TOP and OFFSET clauses so SQL Server returns only the requested page.

Filter contacts by domain in the API

Add a filter parameter to the endpoint call to return only contacts with a specific email domain. The automation includes the filter condition in the SQL WHERE clause before querying.

Combine sorting and pagination for reports

Call the endpoint with both orderby and top parameters to get the first 25 contacts sorted by email. The automation applies both clauses so the response is ordered and limited in a single query.

How it works

  1. Receive Odata API call. Someone calls the Odata API endpoint with optional query parameters such as orderby, top, skip, filter, and expand to request contacts from SQL Server.
  2. Parse query parameters into variables. Extract orderby, top, skip, filter, and expand from the API call and store them as variables for conditional processing and SQL clause construction.
  3. Build SQL clauses from parameters. Check each parameter and prepend the appropriate SQL clause. If orderby is present, add ORDER BY. If top is present, add TOP. If skip is present, add OFFSET.
  4. Query contacts from SQL Server. Run the constructed SQL query against SQL Server to retrieve contacts with the requested sorting, pagination, and filtering applied.
  5. Return contacts as API response. Send the contact records back to the caller as a structured Odata response so the API consumer receives the filtered and sorted data.