Products and Application Users

In this section, you'll create a product resource to represent the product SKU in the inventory management scenario. All instances of the product can be created and share the same metadata. After that, you will add an Application User who creates and manages the Thngs they're responsible for.


Create a Product

Product resources model classes of objects, and can be thought of as SKU-level data, or an object template. We recommend products contain all data that's common to all instances of the object type they represent, such as size, weight, color, model number, barcodes and so on.

Create a product using the Operator API Key (as the manager of the account) to represent the type of product the supply chain will deal in. You create products using a POST /products request. Be sure it is scoped to the correct project to limit visibility by using the project query parameter and the project ID.

Substitutions: :projectId

curl -H "Content-Type: application/json" \
  -H "Authorization: $OPERATOR_API_KEY" \
  -X POST 'https://api.evrythng.com/products?project=:projectId' \
  -d '{
    "name": "Honeysuckle Zombie Brown Ale",
    "description": "A delicious animating local beer for export.",
    "tags": ["export"]
  }'
HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": "U3EtU2k3BD8wQpwwR6EMXgKb",
  "createdAt": 1501509769311,
  "updatedAt": 1501509769311,
  "properties": {},
  "description": "A delicious animating local beer for export.",
  "fn": "Honeysuckle Zombie Brown Ale",
  "name": "Honeysuckle Zombie Brown Ale",
  "tags": ["export"]
}

Create an Application User

Now that you've created the account, project, application, and product resources modelling the supply chain, you need to create additional Platform resources to model the individual bottles of beer. Because these belong to and are managed by the mobile app users, the requests to the API must be authenticated with the user’s Application User API Key, which has permissions centered around managing individual resources. In a real-world scenario, this change in authentication key represents the user creating their own Thngs after logging into the management mobile app, possibly after scanning an object’s barcode.

Create an Application User using the Application API Key you noted earlier, or use a GET projects/:projectId/applications request to find it again. Make a POST /auth/evrythng/users request to create the user resource. Each user must supply at least their first name, last name, an email address, and a password, but the user record can contain much more information.

curl -H "Content-Type: application/json" \
  -H "Authorization: $APPLICATION_API_KEY" \
  -X POST 'https://api.evrythng.com/auth/evrythng/users' \
  -d '{
    "firstName": "Sean",
    "lastName": "Angle",
    "email": "[email protected]",
    "password": "passw0rd"
  }'
HTTP/1.1 201 Created
Content-Type: application/json

{
  "evrythngUser": "U3EQA4aDeXPwQpwRagPwMMhb",
  "activationCode": "DIlB8k6F",
  "status": "inactive",
  "email": "[email protected]"
}

Note that the Application User doesn't receive an Application User API Key until their account is validated. In a real-world application, validation is commonly done using a verification email. For now, you can do this immediately using the API.

To validate the Application User, send the activationCode value from the response to the API in a POST /auth/evrythng/users/:evrythngUser/validate request. The user then receives an Application User API Key that they can use to make requests on their own behalf.

Substitutions: :evrythngUser, :activationCode

curl -H "Content-Type: application/json" \
  -H "Authorization: $APPLICATION_API_KEY" \
  -X POST 'https://api.evrythng.com/auth/evrythng/users/:evrythngUser/validate' \
  -d '{
    "activationCode": ":activationCode"
  }'
HTTP/1.1 201 Created
Content-Type: application/json

{
  "status": "active",
  "evrythngUser": "U3EQA4aDeXPwQpwRagPwMMhb",
  "evrythngApiKey": "S68QqT4sQ8A49XnPMOZ0WS3ZqpF1mOACYhhea42XJ..."
}

The Application User is now activated and their Application User API Key can be seen in the final response. Use this API key to manage resources the user sees and interacts with within the project. Make a note of this API key. You will use it in the next section.