PiShock API Documentation


Obtaining UserID and Token

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);

Custom URL Protocol

On successful login, https://login.pishock.com?proto=web will open as an iframe. If ?proto= is changed it will open a new tab with the protocol of the URL set to the provided ?proto flag.
Example: https://login.pishock.com/?proto=example will open example://{userid}++{token} in a new tab.

Obtaining UserID with API Key

Make a request to https://auth.pishock.com/Auth/GetUserIfAPIKeyValid?apikey={apikey}&username={username}

Ensure that {apikey} and {username} are appropriately replaced

The result will contain some extra information, but all that you need is the UserID field.

Obtaining Devices and Shockers

Your own devices

  • Option 1: UserID + API Key

    Make a request to https://ps.pishock.com/PiShock/GetUserDevices?UserId={userid}&Token={apikey}&api=true
    This will login via API credentials, with this option there is no timeout.

  • Option 2: UserID + Token

    Make a request to https://ps.pishock.com/PiShock/GetUserDevices?UserId={userid}&Token={token}
    This will login as website, with this option your login session will expire after two (2) weeks.

The result will look something like this:

[
    {
        "clientId": 6969, //The hub's id
        "name": "PiShock 1",
        "userId": 123, //your user id
        "username": "username", //your username
        "shockers": [
            {
                "name": "Shocker 1",
                "shockerId": 321,
                "isPaused": false
            }
        ]
    },
    {
        "clientId": 420, //The hub's id
        "name": "PiShock 2",
        "userId": 123, //your user id
        "username": "username", //your username
        "shockers": [
            {
                "name": "Shocker 2",
                "shockerId": 456,
                "isPaused": false
            },
            {
                "name": "Shocker 3",
                "shockerId": 789,
                "isPaused": false
            }
        ]
    },
]

Shared Shockers

  • Option 1: UserID + API Key

    Make a request to https://ps.pishock.com/PiShock/GetShareCodesByOwner?UserId={userid}&Token={apikey}&api=true
  • Option 2: UserID + Token

    Make a request to https://ps.pishock.com/PiShock/GetShareCodesByOwner?UserId={userid}&Token={token}
What is the difference between the two options?

Option 1 (UserID + API Key) allows you to login via API credentials, with this option there is no timeout.
Option 2 (UserID + Token) allows you to login as website, with this option your login session will timeout after two (2) weeks.

The result will look something like this:

{
    "username1": [
        123,
        456
    ],
    "username2": [
        111,
        112,
        113,
        114,
        115
    ]
}
What does this do?

This returns a list of shareID’s grouped by the owner of each Shocker.
To get the required info, such as client and shockerID’s, you need to make a request to https://ps.pishock.com/PiShock/GetShockersByShareIds?UserId={userid}&Token={token}
For each shareID you MUST add &shareIds={id}.

Example

  • Option 1: UserID + API Key

    https://ps.pishock.com/PiShock/GetShockersByShareIds?UserId={userid}&Token={apikey}&shareIds=123&api=true&shareIds=456
  • Option 2: UserID + Token

    https://ps.pishock.com/PiShock/GetShockersByShareIds?UserId={userid}&Token={token}&shareIds=123&shareIds=456
What is the difference between the two options?

Option 1 (UserID + API Key) allows you to login via API credentials, with this option there is no timeout.
Option 2 (UserID + Token) allows you to login as website, with this option your login session will timeout after two (2) weeks.

The result will look something like this:

{
    "username1": [
        {
            "shareId": 123,
            "clientId": 6969,
            "shockerId": 789,
            "shockerName": "Shocker 1",
            "isPaused": false,
            "maxIntensity": 100,
            "canContinuous": true,
            "canShock": true,
            "canVibrate": true,
            "canBeep": true,
            "canLog": true,
            "shareCode": "8D02567BD6BB"
        },
        {
            "shareId": 456,
            "clientId": 6969,
            "shockerId": 790,
            "shockerName": "Shocker 2",
            "isPaused": false,
            "maxIntensity": 100,
            "canContinuous": true,
            "canShock": true,
            "canVibrate": true,
            "canBeep": true,
            "canLog": true,
            "shareCode": "8D02567BD6BA"
        },
    ]
}