Elements Manual
Elements 2 Manual
Elements 2 Manual
  • Welcome 👋
  • QUICK START
    • Elements in Five Minutes or Less
  • General
    • General Concepts
    • N-Tier Architecture
    • Security Model
  • SCRIPTING ENGINE
    • Scripting Engine Overview
      • Intro to Resources and Cloud Functions
      • Horizontal Scaling Model
      • Database Access
      • Server-to-Server API Calls
      • Deploy Cloud Functions via Git
      • Creating and Destroying Resources
      • Cross-Resource Invocation
      • Indexing Resources
      • Coroutines
      • Manifest
  • Core Features
    • Core API Overview
    • Sessions
    • Applications
      • Facebook Application Configuration
      • Firebase Application Configuration
      • Amazon GameOn Application Configuration
      • iOS Application Configuration
      • Android Application Configuration
      • Matchmaking Application Configuration [deprecated]
    • Users and Profiles
    • Digital Goods
    • Progress and Missions
    • Leaderboards
    • Matchmaking
    • Followers
    • Friends
    • Reward Issuance
    • Push Notifications
    • Auth Schemes
    • Save Data
    • Schemas and Metadata Specifications
    • Queries
      • Base Query Syntax
      • Boolean Queries
      • Object Graph Navigation
      • Advanced Operators
        • .ref
        • .name
  • Web 3
    • Omni Chain Support
    • Vaults
    • Wallets
    • Smart Contracts
      • Smart Contracts: Ethereum
      • Smart Contracts: Flow
      • Smart Contracts: Solana
      • Smart Contracts: Neo
    • Know Your Customer
      • Formidium
  • CONFIGURATION
    • Using the Web Console
    • iOS and Android Product Bundles
    • Direct Database Access and Batch Configuration
  • UNITY PLUG-INS
    • Unity Plugin
    • Content Delivery Management and Unity CDN Plugin
  • DEPLOYMENT
    • Deployment Overview
      • Docker Containers
      • AWS Deployment
      • Standalone docker-compose
  • LUA SAMPLES
    • lua Samples
      • main.lua
      • event.lua
      • hello_world.lua
      • model.lua
      • startup.lua
      • HTTP Manifest
        • Example endpoint handler
        • Example operations table
  • RESTful APIs
    • Swagger and Swagger UI
    • Elements 3.0.X (Preview)
      • Applications
      • Friends and Followers
      • Digital Goods and Inventory
      • Leaderboards
      • Missions and Rewards
      • User and Profiles
      • Save Data
      • Custom Metadata
Powered by GitBook
On this page
  • Direct Database Access
  • Batch Configuration
  1. CONFIGURATION

Direct Database Access and Batch Configuration

Directly edit your Mongo database or batch configure digital goods, missions, or other items quickly and easily.

Direct Database Access

You can use a tool like Robo 3T to browse and edit the Mongo database directly. Locally, the DB can be accessed at port 27017. Accessing the database for a remote instance on a service like AWS will require more advanced setup with ssh authentication.

Batch Configuration

If there are a lot of digital goods, missions, or other configurable items to be added to your instance, it may be desirable to batch upload or update many at once. Using bash scripts, it's possible to interact directly with the API to upload data in json format directly to the Elements database.

Item Upload Bash Script Sample

Below is a sample script to upload items defined in JSON. By default it's configured to upload items defined in a JSON file (items.json) in the same directory as the script, to your local Elements instance. You can format the items in the JSON in the same way you see in the example earlier in this document.

This script will also update items if they already exist in the database.

#!/usr/bin/env bash

function post_item() {

    url=$1
    secret=$2
    definition=$3
    name=$(jq -r  '.name' <<< "${definition}")
    id=$(curl -k -X GET "${url}/item/${name}" | jq -r '.id')
    echo "Item id is ${id}"
    if [ -z "$id" ] || [ "$id" = "null" ]
    then
          echo "Creating new item..."
          curl -k -X POST \
          "${url}/item" \
          -H 'Cache-Control: no-cache' \
          -H 'Content-Type: application/json' \
          -H "SocialEngine-SessionSecret: ${secret}" \
          -d "${definition}"
    else
          echo "Updating item..."
          item=$(jq --arg id ${id} '{id: $id} + .' <<< "${definition}")
          curl -k -X PUT \
          "${url}/item/${id}" \
          -H 'Cache-Control: no-cache' \
          -H 'Content-Type: application/json' \
          -H "SocialEngine-SessionSecret: ${secret}" \
          -d "${item}"
    fi
    return $?

}

echo -n "Definitions: (items.json): "
read definitions

echo -n "API (http://localhost:8080/api/rest): "
read url

echo -n "Username:  "
read username

echo -n "Password:  "
read -s password

definitions=${definitions:-"items.json"}

if [ ! -f ${definitions} ]
then
    echo "Definitions not found: ${definitions}"
    exit 1
fi

url=${url:-"http://localhost:8080/api/rest"}

session=$(curl -k -X POST \
  "${url}/session" \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d "{ \"userId\" : \"${username}\", \"password\" : \"${password}\" }")

code=$?

if [ ${code} -ne 0 ]
then
    echo "Failed to create session."
    exit 1
else
    echo "Successfully created session."
    secret=$(echo ${session} | jq -r ".sessionSecret")
fi

jq -c '.[]' $definitions | while read item;
do
    echo "Creating item: ${url} ${secret} ${item}" 
    post_item "${url}" "${secret}" "${item}"
done 

Mission Upload Bash Script Sample

Below is a sample script to upload missions defined in JSON. By default it's configured to upload missions defined in a JSON file (missions.json) in the same directory as the script, to your local Elements instance.

You can format the missions in the JSON in the same way you see in the example earlier in this document.

This script will also update missions if they already exist in the database.

#!/usr/bin/env bash

function post_item() {

    url=$1
    secret=$2
    definition=$3
    name=$(jq -r  '.name' <<< "${definition}")
    id=$(curl -k -X GET "${url}/mission/${name}" | jq -r '.id')
    if [ -z "$id" ]
    then
          echo "${id} is NULL, Creating Item"
          curl -k -X POST \
          "${url}/mission" \
          -H 'Cache-Control: no-cache' \
          -H 'Content-Type: application/json' \
          -H "SocialEngine-SessionSecret: ${secret}" \
          -d "${definition}"
    else
          echo "${id} is NOT NULL, Updating Item"
          item=$(jq --arg id ${id} '{id: $id} + .' <<< "${definition}")
          curl -k -X PUT \
          "${url}/mission/${id}" \
          -H 'Cache-Control: no-cache' \
          -H 'Content-Type: application/json' \
          -H "SocialEngine-SessionSecret: ${secret}" \
          -d "${item}"
    fi
    return $?

}

echo -n "Definitions: (missions.json): "
read definitions

echo -n "API (http://localhost:8080/api/rest): "
read url

echo -n "Username:  "
read username

echo -n "Password:  "
read -s password

definitions=${definitions:-"missions.json"}

if [ ! -f ${definitions} ]
then
    echo "Definitions not found: ${definitions}"
    exit 1
fi

url=${url:-"http://localhost:8080/api/rest"}

session=$(curl -k -X POST \
  "${url}/session" \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d "{ \"userId\" : \"${username}\", \"password\" : \"${password}\" }")

code=$?

if [ ${code} -ne 0 ]
then
    echo "Failed to create session."
    exit 1
else
    echo "Successfully created session."
    secret=$(echo ${session} | jq -r ".sessionSecret")
fi

jq -c '.[]' $definitions | while read item;
do
    post_item "${url}" "${secret}" "${item}"
done 

Product Bundles Upload Bash Script Sample

Below is a sample script to upload product bundles defined in JSON. By default it's configured to upload missions defined in a JSON file (ProductBundles.json) in the same directory as the script, to your local Elements instance. When running the script, you'll also need the ID of the application configuration, since the script can add the bundles to either the iOS or Google Play application configurations.

You can format the product bundles in the JSON in the same way you see in the example earlier in this document.

#!/usr/bin/env bash

function post_item() {

    url=$1
    secret=$2
    definition=$3

    curl -k -X PUT \
        "${url}/application/PTWI/configuration/${appConfigurationId}" \
        -H 'Cache-Control: no-cache' \
        -H 'Content-Type: application/json' \
        -H "SocialEngine-SessionSecret: ${secret}" \
        -d "${definition}"

    return $?

}

echo -n "AppConfigurationId (See web-ui/EditApplication/ProfileId):"
read appConfigurationId

echo -n "Definitions: (ProductBundles.json): "
read definitions

echo -n "API (http://localhost:8080/api/rest): "
read url

echo -n "Username:  "
read username

echo -n "Password:  "
read -s password

definitions=${definitions:-"ProductBundles.json"}

if [ ! -f ${definitions} ]
then
    echo "Definitions not found: ${definitions}"
    exit 1
fi

url=${url:-"http://localhost:8080/api/rest"}

session=$(curl -k -X POST \
  "${url}/session" \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d "{ \"userId\" : \"${username}\", \"password\" : \"${password}\" }")

code=$?

if [ ${code} -ne 0 ]
then
    echo "Failed to create session."
    exit 1
else
    echo "Successfully created session."
    secret=$(echo ${session} | jq -r ".sessionSecret")
fi

product_bundles=`cat ${definitions}`
post_item "${url}" "${secret}" "$product_bundles"
PreviousiOS and Android Product BundlesNextUnity Plugin

Last updated 2 years ago