NOTE: This document has been moved to https://docs.pishock.com/pishock/api-documentation/websocket-api.html and https://docs.pishock.com/pishock/api-documentation/redis.html

Obtaining UserID and Token (requires webserver)

let loginWindow;

//opens the login window prompting the user to login
function login() {
  loginWindow = window.open(
    '<https://login.pishock.com?proto=web>',
    'toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=500,height=800'
  )
}

//once the user logs in this function will be passed the userID and token
//The userID and Token will be used in the rest of these docs for authentication
function receiveMessage(event) {
  if (event.origin !== '<https://login.pishock.com>') {
    return;
  }
  var loginData = event.data;
  const userId = loginData.Id
  const token = loginData.Token;
  loginWindow.close();
}

window.addEventListener('message', receiveMessage, false);

Obtaining UserID with api key

Make a request to

**https://auth.pishock.com/Auth/GetUserIfAPIKeyValid?apikey={apikey}&username={username}**

The result will contain some extra info but all that you need is the UserId field

Obtaining devices and shockers


Sending Commands

Channels

Own: c{clientId}-ops

ShareCode: c{clientId}-sops-{sharecode}

Command Format

{
  "id": "<shocker.id>",
  "m": "<mode>", // 'v', 's', 'b', or 'e'
  "i": "<intensity>", // Could be vibIntensity, shockIntensity or a randomized value
  "d": "<duration>", // Calculated duration in milliseconds
  "r": "<repeating>", // true or false, always set to true.
  "l": {
    "u": "<userID>", // User ID from first step
    "ty": "<type>", // 'sc' for ShareCode, 'api' for Normal
    "w": "<warning_flag>", // true or false, if this is a warning vibrate, it affects the logs
    "h": "<hold>", // true if button is held or continuous is being sent.
    "o": "<origin>" // send to change the name shown in the logs.
  }
}

Redis connection