Getting the user's image

The only way to display a user's profile image is to create an endpoint that finds the user in the database and returns the URL of the image. (The steps are the same as getting the badge's image.)

Step 1: Create an "API" flow

  1. In the Explorer pane, click Create new.
  2. Select API.
  3. Type Get user's image.
  4. Tap the Return key.

Step 2: Configure the "Start" component

  1. Open the Start component.
  2. From the Method dropdown, select GET.
  3. In the URL field, enter /user-image.
  4. Create a query string parameter called id.

Step 3: Get the user from the database

  1. Add a Select component to the flow.
  2. Rename the component to selectUser.
  3. From the Table dropdown, select users.
  4. In the Filter tab, create a condition that checks if Field: id is equal to Start.queryString.id.

Step 4: Check if the user exists

  1. Add an If component to the flow.
  2. Create a condition that checks if selectUser.data is not null or empty.

Step 5: If the user doesn't exist, return an error

  1. Add an End component to the flow.
  2. Connect the If component to the End component via the False branch.
  3. Set the Status Code to 404 Not Found.

Step 6: If the user doesn't exist, return their profile image

  1. Add an End component to the flow.
  2. Connect the If component to the End component via the True branch.
  3. From the Status Code dropdown, select 200 OK.
  4. From the Content Type dropdown, select filePath.
  5. In the Body field, enter selectUser.data[0].profileimg.

This is what the complete flow looks like: