Wix Data APIs: Sample Use Cases & Flows

This article presents sample use cases and corresponding flows that demonstrate how to use the Wix Data APIs together. These can be a helpful starting point as you plan your implementation.

Set up a job board

You can use multiple Data APIs to create a fully configured job board system. This flow creates collections with proper schemas, adds indexes for query optimization, and populates the collections with initial data.

To set up a job board:

  1. Call Create Data Collection to create a companies collection. Include the following properties in your request:

    In the fields array, include fields with these recommended values for type:

    • name, slug, and location: TEXT
    • description: RICH_TEXT
    • logo: IMAGE
    • website: URL

    Set the values in permissions as follows:

    • read: ANYONE so visitors can view the listings.
    • insert, update, and remove: ADMIN so only site owners can manage content.

  2. Call Create Data Collection to create a jobs collection. Include the following properties in your request:

    In the fields array, include fields with these recommended values for type:

    • title, slug, and location, employmentType, status: TEXT
    • description: RICH_TEXT
    • salaryMin and salaryMax: NUMBER
    • postedDate and deadline: DATETIME

    Also include the following fields to add a cross reference for the companies collection created earlier.

    • company: with type set to MULTI_REFERENCE and typeMetadata.multireference.referencedCollectionId set to companies.

    Set permissions to control the collection's access as follows:

    • read: ANYONE so visitors can view the companies' details.
    • insert, update, and remove: ADMIN so only site owners can manage content.

  3. Call Create Index to create an index on the jobs collection for the status and postedDate fields to accelerate queries for open jobs sorted by date.

  4. Call Create Index to create an index on location to accelerate location-based job searches.

  5. Call Bulk Insert Data Items to populate the companies collection with company profiles.

  6. Call Bulk Insert Data Items to populate the jobs collection with job listings, referencing the company IDs from the previous step.

Add fields to an existing collection and migrate data

You can extend an existing collection's schema and migrate data to populate the new fields. This is useful when evolving your data model over time.

To add fields and migrate data:

  1. Call Get Data Collection to retrieve the current jobs collection schema and revision number.
  2. Call Create Data Collection Field for the jobs collection to add a new remote field with type set to BOOLEAN.
  3. Call Query Data Items to retrieve all existing job listings.
  4. Call Bulk Update Data Items to update each job with a remote value based on the location field. For example, set to true if location contains "Remote".
  5. Call Create Index to add an index on the new remote field if you plan to filter by it frequently.

Back up and restore collection data

You can create a backup of your collections before making significant changes, then restore the data if needed. This is useful for protecting against accidental data loss during migrations or bulk updates.

To back up and restore data:

  1. Call Create Backup to create a full backup of your site's collections. The response includes a backupId.
  2. Make your changes to the collections using the Data Items API to insert, update, or remove items.
  3. If you need to revert the changes, call Restore Backup with the backupId from step 1.
  4. Alternatively, call Restore Partial Backup to restore only specific collections by specifying the collection IDs.

Query and aggregate job listings

You can combine querying and aggregation to build rich job search features. This flow retrieves jobs with their company details and calculates hiring statistics.

To query and aggregate job data:

  1. Call Query Data Items with dataCollectionId set to jobs:
    • In query.filter, set status to "open" and location to the target city.
    • In query.sort, sort by postedDate in descending order to show newest jobs first.
    • Set includeReferencedItems to ["company"] to include full company details in the response.
  2. Call Aggregate Data Items to calculate hiring statistics:
    • Set groupingFields to ["location"].
    • Add operations for itemCount (total jobs per location) and average on salaryMax (average maximum salary).
  3. Call Count Data Items with a filter for status equals "open" to display the total number of open positions.
Did this help?