Adding badges to users

This part of the tutorial series explains how to use the users_badges table to create relationships between users and their badges.

Step 1: Create an "API" flow

  1. In the Explorer pane, click Create new.
  2. Select API.
  3. Type Add badge to user.
  4. Tap the Return key.

Step 2: Configure the "Start" component

  1. Open the Start component.
  2. From the Method dropdown, select POST.
  3. In the URL field, enter /add-badge.
  4. Create the following query string parameters: userId and badgeId.

Step 3: Insert (or update) a user-badge relationship

  1. Add an Upsert component to the flow. This component creates a record if it doesn't already exist. If the record does exist, it updates it. This ensures that we never create more than one relationship between the same user and badge.

  2. From the Table dropdown, select users_badges.

  3. Configure the component with the following columns:

    ColumnValueKey
    userIdStart.queryString.userIdYes
    badgeIdStart.queryString.badgeIdYes

Step 4: Create the HTTP response

  1. Add an End component to the flow.
  2. From the Status Code dropdown, select 200 OK.
  3. From the Content Type dropdown, select application/json.
  4. In the Body field, enter Insert.data.

This is what the complete flow looks like: