Tutorial - API

This tutorial demonstrates how to create a new API in SPARQUE Desk that makes the strategy from the Strategy Tutorial accessible to external applications.

Requirements:

Log in

To begin, log in to SPARQUE Desk:

  1. Go to desk.sparque.ai and sign in.


    SPARQUE login screen
  2. Select your workspace from the list of available workspaces.

    After logging in and selecting the workspace, the following menu appears:


    SPARQUE menu

Create a new API

To create a new API:

  1. Click APIs | + Create API.

  2. Enter the name search and click CREATE.

    An empty API is now created.

  3. Click + Add endpoint to create a new API endpoint. Each API can have multiple endpoints. In the creation dialog, enter variation as the endpoint name and click NEXT. Select /baseproduct/STRING -> OBJ as the template and click NEXT again. Review the new endpoint and click CREATE ENDPOINT. The API now has one endpoint. The path variation/p/baseproduct/{STRING} breaks down to:

    • variation: the endpoint's name
    • p: indicates the next path segment is a parameter
    • baseproduct: the parameter name, as defined in the variations strategy
    • {STRING}: a placeholder for the value with which the endpoint is called

    new API endpoint
  4. The endpoint exists but has no functionality yet. To provide functionality, a strategy needs to be assigned. To select a strategy, click the red no strategy button to the right of the endpoint. Click the variations strategy and select the snapshot first version. Then click SELECT.

    The button is no longer red and displays the date and time the strategy snapshot was created.


    API endpoint with selected strategy

Enable the API

To access the API, it needs to be enabled.

  1. At the top is a banner saying "API is not enabled". Click Enable on the right side of the banner. Before the API is enabled a few settings can be changed. For this tutorial, only disable Authentication required and leave the rest as is. Then click ENABLE API.


    enable API
  2. Wait a moment for the API to finish initializing.


    running API
  3. Click on the endpoint to open its result page. Because the endpoint has a parameter and no value has been provided, the result is empty.

  4. On the left, set the value of the baseproduct parameter to P0001. The result updates automatically and shows the two variation products of the base product with SKU P0001.


    API endpoint result page

    Set the value to P1234. The result is empty again. The output is identical to the Testset used in the variations strategy.

  5. To view the result as raw JSON, click the icon with two angle brackets < > in the top right. This is the response format SPARQUE uses to reply to requests.


    API endpoint result page JSON
  6. The API endpoint can also be accessed by external applications. Set the baseproduct parameter back to P0001 to get a result. When hovering over the endpoint path (below the Results heading), a copy icon appears. Click it to save the entire request URL to your clipboard.


    API endpoint URL
  7. For this tutorial, the web browser will be the external application to access the API endpoint. Open a new browser tab, paste the URL into the browser's address bar and press the enter key. The browser shows the same JSON response as previously in SPARQUE Desk.


    API response in browser

    Note: With Authentication required enabled, it would not be possible to simply copy the URL into the browser, because this setting requires the request to contain a token to verify and permit access to the API.

Congratulations! All tutorials have been completed. The basics of virtualizing data with datasets, configuring a strategy to apply logic, and making the result of a strategy available to external applications are now covered.