Flexigift Service API

Tutorial: Add a User

The Flexigift service allows users to pay for their Amazon purchases with third-party gift cards. This tutorial will teach you how to add a new user to Flexigift and fetch your new user’s details.

Allow 30 minutes to complete this lesson.

Prerequisites

Note: This tutorial assumes that the Flexigift service is running at http://localhost:3000. Remember to point to your own host when you adapt the code samples to your own environment.

Overview

The following procedures will teach you how to Create a new user and to Fetch your new user’s details. When you’ve completed the procedures you will have a new user ready to receive gift cards.

Create a new user

You create new users in the system with the POST method of the Create a User API.

  1. Submit a Create a User request with the following details:

    • user_id: The user’s Flexigift account ID. This is defined by you.
    • amazon_id: The user’s Amazon account ID.
    • name: The user’s full name.
    • email: The user’s email address.
    • gift_cards: An array of the user’s gift card IDs.

    Example request:

     curl -POST -H "Content-type: application/json" -d '  {
         "user_id": "user005",
         "amazon_id": "amz9876",
         "name": "Steve Stevens",
         "email": "steve.stevens@example.com",
         "gift_cards": ["hanes-gc-004","gap-gc-005"]  
     }' 'http://localhost:3000/users'
    

    The service responds with the user details that you submitted plus a unique id that the system generates automatically.

    Example response:

     {
     "user_id": "user005",
     "amazon_id": "amz9876",
     "name": "Steve Stevens",
     "email": "steve.stevens@example.com",
     "gift_cards": [
         "hanes-gc-004",
         "gap-gc-005"
     ],
     "id": 5
     }
    
  2. Verify that the response data matches the user details that you submitted.

    If the data matches, congratulations! Your new user is in the system and ready to be spend their gift cards. Note the unique id; you will need to know it if you want to fetch your user’s details later.

Fetch your new user’s details

You can fetch your user’s details any time with the GET method of the Users resource and the instance’s unique id.

Example Get a User request:

curl http://localhost:3000/users/5

Response:

{
  "user_id": "user005",
  "amazon_id": "amz9876",
  "name": "Steve Stevens",
  "email": "steve.stevens@example.com",
  "gift_cards": [
    "hanes-gc-004",
    "gap-gc-005"
  ],
  "id": 5
}

What next?

Now that you have a user in the system, try these next steps: