REST API
Getting Started

Getting Started

The REST API is a tracking API designed to enable game developers to send in-game events from their games to the Earn Alliance platform. This API allows developers to integrate their games with the Earn Alliance Challenge feature, facilitating the tracking and reporting of user activities within the game.

Base URL:

The base URL for accessing the REST API is: https://events.earnalliance.com/v2 (opens in a new tab)

Authentication

To use the REST API, developers need to obtain the following credentials from Earn Alliance:

  • Client ID: Unique identifier for the client application.
  • Client Secret: Secret key associated with the client application.
  • Game ID: Unique identifier for the game sending the requests.

Request Headers

The following headers need to be included in the request:

  • x-client-id: The Client ID provided by Earn Alliance.
  • x-timestamp: Current Unix timestamp in milliseconds.
  • x-signature: Generated signature based on the request body, timestamp, Client ID and Client Secret.

Signature Generation

To generate the signature, follow these steps:

  1. Convert the JSON request body to a string.
  2. Construct a message by concatenating the following components:
    • Client ID
    • Current Unix timestamp (in ms)
    • Request body as a string

Use the constructed message to create an HMAC SHA256 hash using the Client Secret. The resulting hash is the generated signature.

// example signature generation in javascript
const crypto = require("crypto");
const clientId = "<client id>";
const clientSecret = "<client secret>";
 
// message body
const body = {
    ...
}
const ts = Date.now()
const message = `${clientId}${ts}${JSON.stringify(body)}`;
 
const signature = crypto
  .createHmac('sha256', clientSecret)
  .update(message)
  .digest('hex')