Getting started overview

Integrating with the Wix API allows developers to programmatically extend and customize Wix websites, manage data, and connect with external applications. This guide provides a structured path to initiate development, covering account setup, credential acquisition, and the execution of a foundational API request. The Wix API supports various functionalities, including managing site content, e-commerce operations, booking systems, and user data. It is designed to work with Wix's core products like the Wix Editor, Wix Studio, and Wix Headless, providing a comprehensive set of tools for developers to build custom solutions on the Wix platform.

Before making API calls, developers typically require a Wix account and a site configured with the necessary applications. The primary method for interacting with the Wix API involves RESTful HTTP requests, often secured using OAuth 2.0 for app integrations or API keys for direct service access. Wix provides a JavaScript SDK to facilitate client-side development and offers detailed documentation for its various API services, including Wix Data, E-commerce, and Bookings.

The following table outlines the essential steps to get started with the Wix API:

Step What to Do Where to Do It
1. Create Wix Account Sign up for a new Wix account or log into an existing one. Wix Homepage
2. Create/Select a Site Set up a new Wix site or choose an existing one to work with. Wix Dashboard
3. Enable Dev Mode Activate Developer Mode in your Wix site editor to access Velo by Wix. Wix Editor > Dev Mode
4. Install Apps (if needed) Install relevant Wix apps (e.g., Wix Stores, Wix Bookings) if your integration requires their APIs. Wix App Market
5. Obtain API Keys/Tokens Generate an API key or set up OAuth 2.0 credentials for authentication. Wix Dev Center / Site Dashboard > Settings
6. Make First Request Send a simple API request to verify authentication and connectivity. Using cURL, Postman, or a programming language (e.g., JavaScript)

Create an account and get keys

To begin using the Wix API, the first step is to create or log into a Wix account. If you do not have one, you can sign up for a free account on the Wix homepage. While a free plan is available, access to certain advanced API functionalities, especially those related to e-commerce or specific business solutions, may require a paid Wix plan. Once your account is set up, you will need to create a new Wix site or select an existing one from your dashboard. Most API interactions are scoped to a specific Wix site.

Enabling Developer Mode

For many API interactions, especially those utilizing Velo by Wix, you will need to enable Developer Mode within your site's editor. This provides access to the backend code and database collections, which are often targets for API requests. To enable it, navigate to your site in the Wix Editor, then find the 'Dev Mode' option in the top menu.

Obtaining API Keys or OAuth Credentials

Wix API uses different authentication methods depending on the integration type:

  • API Keys: For direct server-to-server integrations with specific Wix services, you might use API keys. These are typically generated within your Wix site's dashboard under 'Settings' or within the Wix Dev Center. Ensure these keys are kept secure and not exposed client-side.
  • OAuth 2.0: For building applications that integrate with Wix sites on behalf of users (e.g., a public app in the Wix App Market), OAuth 2.0 is the standard authentication flow. This involves registering your application, obtaining client ID and client secret, and implementing the OAuth authorization code grant flow. This method is more complex but provides secure delegated access without sharing user credentials. The OAuth 2.0 specification is maintained by the IETF.

For a quick start, especially for testing, API keys are often simpler if the specific API supports them. Refer to the Wix API overview for detailed instructions on obtaining the appropriate credentials for your specific use case.

Your first request

After setting up your account and obtaining your API credentials, you can make your first API request. A common starting point is to interact with the Wix Data API, which allows you to manage collections within your Wix site's database. This example demonstrates fetching items from a collection.

Before proceeding, ensure you have:

  1. A Wix site with Developer Mode enabled.
  2. A database collection created (e.g., named MyCollection) with some items.
  3. An API key with appropriate permissions for Wix Data.

Example 1: Fetch Items from a Wix Data Collection (using cURL)

This cURL command retrieves a list of items from a specified collection. Replace YOUR_API_KEY and YOUR_SITE_ID with your actual credentials and site ID.

curl --request POST \
  --url 'https://www.wixapis.com/_api/wix-data/v2/collections/query-items' \
  --header 'Authorization: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{ \
    "query": { \
      "collectionName": "MyCollection", \
      "filter": {}, \
      "paging": { \
        "limit": 10, \
        "offset": 0 \
      } \
    } \
  }'

Explanation:

  • --request POST: Specifies the HTTP method as POST, as many Wix Data API endpoints use POST for queries.
  • --url 'https://www.wixapis.com/_api/wix-data/v2/collections/query-items': The endpoint for querying items in a collection.
  • --header 'Authorization: YOUR_API_KEY': Passes your API key in the Authorization header.
  • --header 'Content-Type: application/json': Indicates that the request body is in JSON format.
  • --data '{...}': The JSON payload defining the query, including the collectionName, an empty filter (to retrieve all items), and paging parameters.

Example 2: Fetch Items from a Wix Data Collection (using JavaScript)

For client-side or Node.js applications, you can use JavaScript. Ensure you replace the placeholders with your actual values.

const fetch = require('node-fetch'); // For Node.js, install with npm install node-fetch

const API_KEY = 'YOUR_API_KEY';
const SITE_ID = 'YOUR_SITE_ID'; // Often not directly needed for API key auth, but good to know
const COLLECTION_NAME = 'MyCollection';

async function getCollectionItems() {
  try {
    const response = await fetch('https://www.wixapis.com/_api/wix-data/v2/collections/query-items', {
      method: 'POST',
      headers: {
        'Authorization': API_KEY,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        query: {
          collectionName: COLLECTION_NAME,
          filter: {},
          paging: {
            limit: 10,
            offset: 0
          }
        }
      })
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    console.log('Fetched items:', data.items);
  } catch (error) {
    console.error('Error fetching collection items:', error);
  }
}

getCollectionItems();

Upon successful execution, either example should return a JSON object containing an items array with the data from your MyCollection.

Common next steps

After successfully making your first API call, consider these common next steps to further your integration with the Wix API:

  1. Explore Other APIs: Wix offers a wide range of APIs beyond Wix Data, including Wix Stores API for e-commerce, Wix Bookings API for scheduling, and Wix Events API. Review the Wix API Reference to identify relevant services for your project.
  2. Implement OAuth 2.0 (for Public Apps): If you plan to build an application for multiple Wix users or list it in the Wix App Market, migrating from API keys to OAuth 2.0 is crucial for secure and scalable authentication. This involves setting up your app in the Wix Dev Center and implementing the OAuth flow.
  3. Utilize Webhooks: To receive real-time notifications about events happening on a Wix site (e.g., new order, form submission), implement webhooks. This allows your application to react to changes without constant polling. Consult the Wix API documentation on webhooks for setup instructions.
  4. Error Handling and Logging: Implement robust error handling in your application to gracefully manage API failures, rate limits, and network issues. Log API requests and responses for debugging and monitoring purposes.
  5. Consider the JavaScript SDK: For client-side development within Wix or Node.js environments, leverage the official Wix JavaScript SDK. It can simplify API interactions and handle authentication complexities.
  6. Performance Optimization: As your application grows, optimize API calls by using pagination, filtering, and batch operations where available to reduce load times and resource consumption.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are some troubleshooting steps:

  • Check API Key/Authorization Header: Verify that your API key is correct and included in the Authorization header (or as required by the specific API endpoint). A common error is a missing or malformed header. Ensure the key has the necessary permissions for the API you are calling.
  • Verify Endpoint URL: Double-check the API endpoint URL for typos or incorrect versions (e.g., v1 vs. v2). Refer to the Wix API Reference for the exact URL.
  • Examine Request Body (for POST/PUT): If your request includes a JSON body, ensure it is valid JSON and matches the schema expected by the API. Small syntax errors (e.g., missing commas, unquoted keys) can lead to parsing errors.
  • Review HTTP Status Codes: The HTTP status code in the API response provides crucial information:
    • 400 Bad Request: Often indicates an issue with your request body or parameters.
    • 401 Unauthorized: Authentication failed; check your API key or OAuth token.
    • 403 Forbidden: Your credentials are valid, but they lack the necessary permissions to access the resource.
    • 404 Not Found: The requested resource or endpoint does not exist.
    • 5xx Server Error: An issue on the Wix API server side.
  • Check Developer Console/Logs: For client-side JavaScript, use your browser's developer console to inspect network requests and responses. For server-side code, review your application logs for any errors.
  • Consult Wix Documentation: The Wix Developer Documentation provides detailed error codes and explanations for each API service. Search for the specific error message or status code you received.
  • CORS Issues: If calling the API from a browser, Cross-Origin Resource Sharing (CORS) policies might block requests from unauthorized origins. Ensure your Wix site or application is configured to allow requests from your development environment's domain.