Elements Manual
Elements 3 Manual
Elements 3 Manual
  • Welcome 👋
  • QUICK START
    • Elements in Five Minutes or Less
    • Accessing the Web UI (CRM)
    • Creating A User
  • General
    • General Concepts
    • N-Tier Architecture
    • Security Model
  • Core Features
    • Core API Overview
    • Sessions
    • Applications
    • Users and Profiles
    • Digital Goods
    • Progress and Missions
    • Leaderboards
    • Matchmaking
    • Followers
    • Friends
    • Reward Issuance
    • Save Data
    • Schemas and Metadata Specifications
    • Queries
      • Base Query Syntax
      • Boolean Queries
      • Object Graph Navigation
      • Advanced Operators
        • .ref
        • .name
    • Custom Code
      • Element Structure
      • RESTful APIs
      • Websockets
    • Auth Schemes
      • OIDC
      • OAuth2
  • Web 3
    • Omni Chain Support
    • Vaults
    • Wallets
    • Smart Contracts
      • Smart Contracts: Ethereum
      • Smart Contracts: Flow
      • Smart Contracts: Solana
      • Smart Contracts: Neo
  • CONFIGURATION
    • Direct Database Access and Batch Configuration
    • Batch Samples
      • Item Upload Bash Script Sample
      • Mission Upload Bash Script Sample
  • RESTful APIs
    • Swagger and Swagger UI
    • API Specification
      • /application
      • /application/configuration
      • /auth
      • /auth_scheme
        • /custom
        • /oauth2
        • /oidc
      • /blockchain
      • /followee
      • /follower
      • /friend
      • /google
      • /index
      • /inventory
      • /item
      • /large_object
      • /leaderboard
      • /rank
      • /score
      • /match
      • /mission
      • /progress
      • /reward_issuance
      • /schedule
      • /notification
      • /profile
      • /save_data
      • /metadata_spec
      • /mock_session
      • /session
      • /health
      • /version
      • /signup
      • /user
    • Javadocs
  • Releases
    • 3.1 Release Notes
Powered by GitBook
On this page
  1. CONFIGURATION
  2. Batch Samples

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 "Elements-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 "Elements-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 
PreviousItem Upload Bash Script SampleNextSwagger and Swagger UI

Last updated 1 month ago