Link Search Menu Expand Document

REST API for Snapyr

The Snapyr REST API makes it easy to post user traits and events from your website or app to the Snapyr platform, which are used to power your campaigns and dynamic content.

Headers

Authentication

Authenticate to the Snapyr API by sending your workspace’s API Key along with a request.

You can create a workspace API Key directly in the Snapyr App by following these steps:

  • Click the user icon at the top right
  • Select your Organization in the dropdown
  • Click “Workspaces” in the left panel
  • Click on the workspace you want to create an API key for
  • In the right panel, select the “API Keys” tab
  • Click the “+ Add New Key” button
  • Enter a value for your API key and click “Save & Generate”

Authentication uses HTTP Basic Auth, which involves a username:password that is base64 encoded and prepended with the string Basic.

For example, take the Snapyr API Key, ‘abc123’, as the username, add a colon, and keep the password field empty. After base64 encoding ‘abc123:’ becomes ‘YWJjMTIzOg==’; and this is passed in the authorization header like so:

'Authorization: Basic YWJjMTIzOg=='

The following command can be used to generate the auth header:

echo -n '$YOUR_API_KEY:' | openssl base64

Content-Type

To send data to Snapyr’s REST API, a content-type header must be set to 'application/json'.

Identify

Identify ties a user to their actions and records traits about them. It includes a unique User ID and any optional traits you know about them.

Traits are the metadata that applies to your users, such as Age, Country, Games Won, etc. These values can be numbers, text, dates, or boolean (true/false) data types. Traits passed into Snapyr can be used to build highly personalized campaigns and content for your users.

Snapyr recommends calling identify a single time when the user’s account is first created, and only identifying again later when the user traits change.

Please note, identify & track both use the same endpoint.

POST https://engine.snapyr.com/v1/batch

{
  "userId": "065rm9bo7mg2d",
  "traits": {
    "email": "boneill@snapyr.com",
    "name": "Brian O'Neill",
    "games_played": "5",
    "account_balance": "250.00",
    "games_won": 3,
    "unsubscribed": false
  },
  "context": {
    "ip": "14.2.62.55"
  },
  "timestamp": "2022-04-05T00:28:07.349Z"
}

Traits can be used in the WHEN, IF, and SET blocks and are primariliy used for defining Audiences, which are used in the FOR block. Additionally, traits can be used as merge tags to populate dynamic text in the creative being delivered to your users. To learn more about using Traits in Snapyr, please check out our Knowledge Base

Track

Track records the actions your users perform. Every action triggers an event, which can also have associated properties.

You’ll want to track events that are indicators of success for your site, like Sign Up, Purchase or Game Played.

To get started, try tracking just a few important events. You can always add more later.

Please note, track & identify both use the same endpoint.

POST https://engine.snapyr.com/v1/batch

{
  "userId":  "065rm9bo7mg2d",
  "event": "gameplayed",
  "properties": {
    "level": "2",
    "final_score": "30"
   },
  "context": {
    "ip": "14.2.62.55"
  },
  "timestamp": "2022-04-05T00:44:19.126Z"
}

Track event properties can be anything you want to record and use in a Snapyr campaign. Events can be used in the WHEN and IF blocks and can also be used to define Audiences, which are used in the FOR block. To learn more about using events and properties in Snapyr campaigns, please check out our Knowledge Base.

If you have any questions, please contact support@snapyr.com.