Creating users

We're over half-way through this tutorial series and now we can start connecting the different pieces together by creating some users. Users will have points, a level, and zero or more badges.

Step 1: Set up the database tables

We need to create two database table: one for the users themselves and one to store the relationships between the users and their badges.

To create a database table for the users:

  1. Create a table called users.

  2. Configure the table with the following columns:

    NameData TypeNullableDefault ValueReference
    IdGuidNo
    nameStringNo
    profileimgFileNo
    descriptionStringNo
    pointsIntegerNo
    dateCreatedDateTimeNo{datetime.utcnow}
    levelReferenceYeslevels

To create a table for the relationships between the users and their badges:

  1. Create a table called users_badges.

  2. Configure the table with the following columns:

    NameData TypeDefault ValueReference
    userIdReferenceusers
    badgeIdReferencebadges
    dateaddedDateTime{datetime.utcnow}

Step 2: Create an "API" flow

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

Step 3: Configure the "Start" component

  1. Open the Start component.

  2. From the Method dropdown, select POST.

  3. In the URL field, enter /user.

  4. From the Input Type dropdown, select Json.

  5. Copy the following JSON Schema into the Input Schema field:

    {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "profileimg": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "points": {
          "type": "number"
        },
        "dateCreated": {
          "type": "datetime"
        }
      }
    }
    

Step 4: Save the user's profile image

  1. Add a Save File component to the flow.
  2. In the File Name field, enter Start.body.name + ".png".
  3. In the Content Type field, enter image/png.
  4. In the Content (Base64 Encoded) field, enter Start.body.profileimg.

Step 5: Insert the user into the database

  1. Add an Insert component to the flow.

  2. From the Table dropdown, select users.

  3. Configure the component with the following columns:

    ColumnValue
    nameStart.body.name
    profileimgSave_File.path
    descriptionStart.body.description
    pointsStart.body.points
    dateCreatedStart.body.dateCreated

Step 6: Create the HTTP response

  1. Add an End component to the flow.

  2. Configure the component with the following properties:

    PropertyValue
    Status Code200 OK
    Content Typeapplication/json
    BodyInsert.data

This is what the complete flow looks like: