Hiro TypeScript Reference #

This page provides samples for working with Hiro game systems in TypeScript.

Inventory #

List items #

List all inventory items defined in the codex, optionally filtered by category.

1
2
3
4
5
6
const request : InventoryListRequest = {
    item_category: "weapons"
};

const inventoryList = await hiroClient.inventoryList(session, request);
console.log(inventoryList);

List user inventory items #

List all inventory items owned by the player, optionally filtered by category.

1
2
3
4
5
6
const request : InventoryListRequest = {
    item_category: "weapons"
};

const inventoryList = await hiroClient.inventoryListInventory(session, request);
console.log(inventoryList);

Consume inventory items #

Consume one or more inventory items owned by the player.

1
2
3
4
5
6
7
8
const request : InventoryConsumeRequest = {
    items: {
        "health_potion": "1"
    }
};

const consumeRewards = hiroClient.inventoryConsume(session, request);
console.log(consumeRewards);

Grant inventory items #

Grant one or more inventory items to the player.

1
2
3
4
5
6
7
8
const request : InventoryGrantRequest = {
    items: {
        "bronze_sword": "1"
    }
};

const grantRewards = await hiroClient.inventoryGrant(session, request);
console.log(grantRewards);

Update inventory items #

Update the properties on one or more inventory items owned by the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
const request : InventoryUpdateItemsRequest = {
    item_updates: {
        "bronze_sword": {
            string_properties: {
                "example_property": "example_value"
            },
            numeric_properties: {
                "numeric_properties": 10
            }
        }
    }
};

const updateAck = await hiroClient.inventoryUpdate(session, request);
console.log(updateAck);

Economy #

Donation claim #

Claim one or more rewards which are partially or full donated by other players.

1
2
3
4
5
6
const request : EconomyDonationClaimRequest = {
    donation_ids: ["donation_1", "donation_2"]
};

const donationRewards = await hiroClient.economyDonationClaim(session, request);
console.log(donationRewards);

Donate some resource (currencies, items, etc.) to a user by donation ID.

1
2
3
4
5
6
7
const request : EconomyDonationGiveRequest = {
    user_id: "user_id",
    donation_id: "donation_1"
};

const updateAck = await hiroClient.economyDonationGive(session, request);
console.log(updateAck);

Get donation progress #

Get progress on one or more donations for a set of players by their IDs.

1
2
3
4
5
6
const request : EconomyDonationGetRequest = {
    ids: ["donation_1", "donation_2"]
};

const donations = await hiroClient.economyDonationGet(session, request);
console.log(donations);

Request a donation #

Request a donation which other players can contribute into.

1
2
3
4
5
6
const request : EconomyDonationRequest = {
    donation_id: "donation_1"
};

const donationAck = await hiroClient.economyDonationRequest(session, request);
console.log(donationAck);

Get store items #

Get all store items defined in the Virtual Store.

1
2
3
4
5
6
const request : EconomyListRequest = {
    store_type: EconomyStoreType.AppleAppStore
};

const economyList = await hiroClient.economyStoreGet(session, request);
console.log(economyList);

Grant currencies or reward modifiers #

Grant one or more currencies or reward modifiers to te player.

1
2
3
4
5
6
7
8
const request : EconomyGrantRequest = {
    currencies: {
        "coins": "100"
    }
};

const updateAck = await hiroClient.economyGrant(session, request);
console.log(updateAck);

Send a purchase intent #

Send a marker of intent to purchase by the player.

1
2
3
4
5
6
7
const request : EconomyPurchaseIntentRequest = {
    item_id: "item_1",
    store_type: EconomyStoreType.AppleAppStore,
    sku: "sku_1"
};

await hiroClient.economyPurchaseIntent(session, request);

Purchase a store item #

Purchase a store item by the player.

1
2
3
4
5
6
7
8
const request : EconomyPurchaseRequest = {
    item_id: "item_1",
    store_type: EconomyStoreType.AppleAppStore,
    receipt: "<receipt>"
};

const purchaseAck = await hiroClient.economyPurchaseItem(session, request);
console.log(purchaseAck);

Get ad placement status #

Get the current status on an Ad placement which may have been rewarded.

1
2
3
4
5
6
7
8
const request : EconomyPlacementStatusRequest = {
    reward_id: "reward_1",
    placement_id: "placement_1",
    count: 0
};

const placementStatus = await hiroClient.economyPlacementStatus(session, request);
console.log(placementStatus);

Start a new ad placement #

Start a new Ad placement by placement ID.

1
2
3
4
5
6
const request : EconomyPlacementStartRequest = {
    placement_id: "placement_1"
};

const placementStatus = await hiroClient.economyPlacementStart(session, request);
console.log(placementStatus);

Placement success #

Webhook RPC to handle Rewarded Video Ad placement success callbacks.

1
await hiroClient.eonomyPlacementSuccess(session);

Placement fail #

Webhook RPC to handle Rewarded Video Ad placement failure callbacks.

1
hiroClient.economyPlacementFail(session);

Achievements #

Get all achievements #

Get all achievements with progress accumulated by the player.

1
2
const achievementList = await hiroClient.achievementsGet(session);
console.log(achievementList);

Claim achievements #

Claim one or more achievements which have completed their progress.

1
2
3
4
5
6
7
const request : AchievementsClaimRequest = {
    ids: ["achievement_1", "achievement_2"],
    claim_total_reward: true
};

const updateAck = await hiroClient.achievementsClaim(session, request);
console.log(updateAck);

Update achievement progress #

Update one or more achievements with the same progress amount.

1
2
3
4
5
6
7
const request : AchievementsUpdateRequest = {
    ids: ["achievement_1", "achievement_2"],
    amount: 1
};

const achievementsAck = await hiroClient.achievementsUpdate(session, request);
console.log(achievementsAck);

Energy #

Get all energies #

Get the energies and their current timers for the player.

1
2
const energyList = await hiroClient.energyGet(session);
console.log(energyList);

Spend one or more energies #

Spend one or more energies for the player.

1
2
3
4
5
6
7
8
9
const request : EnergySpendRequest = {
    amounts: {
        "power": 10,
        "tickets": 1
    }
};

const energySpendRewards = await hiroClient.energySpend(session, request);
console.log(energySpendRewards);

Tutorials #

Get all tutorials #

Get the tutorials and current progress step for the player.

1
2
const tutorialList = await hiroClient.tutorialGet(session);
console.log(tutorialList);

Accept a tutorial #

Accept an offer to step through a tutorial.

1
2
3
4
5
6
const request : TutorialAcceptRequest = {
    id: "tutorial_1"
};

const tutorial = await hiroClient.tutorialsAccept(session, request);
console.log(tutorial);

Decline a tutorial #

Decline an offer to start a tutorial.

1
2
3
4
5
6
const request : TutorialDeclineRequest = {
    id: "tutorial_1"
};

const tutorial = await hiroClient.tutorialsDecline(session, request);
console.log(tutorial);

Abandon a tutorial #

Abandon progress on a tutorial.

1
2
3
4
5
6
const request : TutorialAbandonRequest = {
    id: "tutorial_1"
};

const tutorial = await hiroClient.tutorialsAbandon(session, request);
console.log(tutorial);

Update progress of a tutorial #

Update the current progress step in the tutorial by ID.

1
2
3
4
5
6
7
const request : TutorialUpdateRequest = {
    id: "tutorial_1",
    step: 1
};

const tutorialList = await hiroClient.tutorialsUpdate(session, request);
console.log(tutorialList);

Teams #

Create a team #

Create a team which other players can join.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
const request : TeamCreateRequest = {
  name: "Example team",
  desc: "Example description",
  open: true,
  icon: "icon.png",
  lang_tag: "en",
  setup_metadata: ""
};

const team = await hiroClient.teamsCreate(session, request);
console.log(team);

List one or more teams #

List one or more teams which the player can join.

1
2
3
4
5
6
7
8
const request : TeamListRequest = {
    cursor: "",
    location: "UK",
    limit: 100
};

const teamList = await hiroClient.teamsList(session, request);
console.log(teamList);

Search for a team #

Search for a team by name or optional short code.

1
2
3
4
5
6
7
const request : TeamSearchRequest = {
    input: "heroes",
    limit: 100
};

const teamList = await hiroClient.teamSearch(session, request);
console.log(teamList);

Send team chat message #

Write a chat message to the Team’s chat channel.

1
2
3
4
5
6
7
const request : TeamWriteChatMessageRequest = {
    id: "team_1",
    content: "{\"message\":\"Hey everyone!\"}"
};

const channelMessageAck = await hiroClient.teamsWriteChatMessage(session, request);
console.log(channelMessageAck);

Unlockables #

Create a random unlockable #

Create a random unlockable to assign to a slot (or overflow) unless there are no slots.

1
2
const unlockablesList = await hiroClient.unlockablesCreate(session);
console.log(unlockablesList);

Get in progress unlockables #

Get the unlockables which are currently in progress for the player.

1
2
const unlockablesList = await hiroClient.unlockablesGet(session, request);
console.log(unlockablesList);

Start an unlock #

Start the unlock timer for an unlockable in the specified slot.

1
2
3
4
5
6
const request : UnlockablesRequest = {
    instance_id: "unlockable_instance_1"
};

const unlockablesList = await hiroClient.unlockablesUnlockStart(session, request);
console.log(unlockablesList);

Purchase an unlockable #

Purchase an unlockable with soft currency based on the remainder cost calculated by the offset left to wait.

1
2
3
4
5
6
const request : UnlockablesRequest = {
    instance_id: "unlockable_instance_1"
};

const unlockablesList = await hiroClient.unlockablesPurchaseUnlock(session, request);
console.log(unlockablesList);

Purchase a new unlockable slot #

Purchase a new slot to be used to store unlockables.

1
2
const unlockablesList = await hiroClient.unlockablesPurchaseSlot(session);
console.log(unlockablesList);

Claim an unlockable #

Claim an unlockable whose start timer has completed or completion was fast tracked with a purchase.

1
2
3
4
5
6
const request : UnlockablesRequest = {
    instance_id: "unlockable_instance_1"
};

const unlockablesList = await hiroClient.unlockablesClaim(session, request);
console.log(unlockablesList);

Base #

Rate app #

Send feedback to the game’s developers over email.

1
2
3
4
5
6
const request : RateAppRequest {
    score: 9,
    message: "It's a great game, love it!"
}

await HiroClient.baseRateApp(session, request);

Set device prefs #

Update or create the mobile push device tokens and preferences for the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
const request : DevicePrefsRequest = {
    device_id: "device_id",
    push_token_android: "android_push_token",
    push_token_ios: "ios_push_token",
    preferences: {
        "dark_mode": true
    }
};

await hiroClient.baseSetDevicePrefs(session, request);

Leaderboards #

Get all leaderboards #

Get the leaderboards defined for the game.

1
2
const leaderboardConfigList = await hiroClient.leaderboardsConfigGet(session);
console.log(leaderboardConfigList);

Event Leaderboards #

Get an event leaderboard #

Get a specified event leaderboard defined for the game.

1
2
3
4
5
6
const request : EventLeaderboardGet = {
    id: "leaderboard_1"
};

const eventLeaderboard = await hiroClient.eventLeaderboardGet(session, request);
console.log(eventLeaderboard);

Update event leaderboard record #

Update an event leaderboard record for a user.

1
2
3
4
5
6
7
8
const request : EventLeaderboardUpdate = {
    id: "leaderboard_1",
    score: 100,
    subscore: 10
};

const eventLeaderboard = await hiroClient.eventLeaderboardUpdate(session, request);
console.log(eventLeaderboard);

Claim event leaderboard reward #

Claim an event leaderboard reward for a user.

1
2
3
4
5
6
const request : EventLeaderboardClaim = {
    id: "leaderboard_1"
};

const eventLeaderboard = await hiroClient.eventLeaderboardClaim(session, request);
console.log(eventLeaderboard);

Roll a new cohort #

Roll a new cohort for the specified event leaderboard.

1
2
3
4
5
6
const request : EventLeaderboardRoll = {
    id: "leaderboard_1"
};

const eventLeaderboard = await hiroClient.eventLeaderboardRoll(session, request);
console.log(eventLeaderboard);

Stats #

Get all stats #

Get all stats.

1
2
const statList = await hiroClient.statsGet(session);
console.log(statList);

Update stats for the player #

Update stats.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
const request : StatUpdateRequest = {
    public: [{
        name: "public_stat_1",
        value: 100,
        operator: StatUpdateOperator.Set
    }],
    private: [{
        name: "private_stat_1",
        value: 100,
        operator: StatUpdateOperator.Set
    }]
};

const statList = await hiroClient.statsUpdate(session, request);
console.log(statList);

Progression #

Get all progressions #

Get progressions.

1
2
const progressionList = await hiroClient.progressionsGet(session);
console.log(progressionsList);

Purchase progression #

Purchase a progression for permanent unlock, if supported.

1
2
3
4
5
const request : ProgressionPurchaseRequest = {
    id: "progression_1"
};

const progressionList = await hiroClient.progressionsPurchase(session, request);