Skip to content

Instantly share code, notes, and snippets.

@wmathes
Last active May 3, 2019 07:56
Show Gist options
  • Save wmathes/d479a8665f4c91bba2e934a4ceeb651e to your computer and use it in GitHub Desktop.
Save wmathes/d479a8665f4c91bba2e934a4ceeb651e to your computer and use it in GitHub Desktop.

ScreenCloud GraphQL Guide

This is a short description on how to use the Signage Next GraphQL API.

What is GraphQL?

IF you have 14 minutes, then have a look at this YouTube video: "14 minute What is GraphQL?".

In short GraphQL is a query language, which queries a graph datatree, hence the name GraphQL. // todo: add more stuff here

ScreenCloud Signage GraphQL

We offer a single GraphQL endpoint for all interactions with Signage. You'll need to be authenticated in order to perform most queries, which requires an API Access Token.

Create a token

In Signage, go to the admin panel and open the developer-tab. Click "New Key".

You'll need to provide a name and should assign a few access rights to that token. For simplicity you can choose "Grant full access".

If you're an org administrator or owner, you can select the "System User"-option, which assigns the key to and org-based system user. This allows for the key to persist even if your account becomes inactive or deleted.

Click "Create Key" and a new popup will show your API Access Token. Store it away and keep it safe as every action performed with it, is performed and logged in your name. Note that the key will be displayed only once and can't be retrieved later on anymore.

You may however create as many tokes as you like.

Managing tokens

All your tokens are displayed in the developer-tab and can be renamed, edited, disabled or permanently deleted.

Using a token

When querying the GQL endpoint, you'll have to send an Authorization-header with a value of bearer <your token>

Quick introduction to Altair

Most IDEs by now offer decent GraphQL support, but there are also a lot of great standalone tools and of course you can use Postman or simply CURL to get the job done.

One tool which is remarkebly simple and offers a great code support is the Altair GraphQL Client both in the browser and standalone on your desktop.

Configuration

You'll need to do two things to be ready.

First copy-paste the GraphQL endpoint url from the developer-page in signage into Altair. It should immediately try to introspect the endpoint and populate all of its documentation. Click on "Docs" to deep-dive into all available data queries and mutations at any time.

Next set set your Authorization-header using the asterisk icon in the left sidebar. The value should be bearer <your token>

Start querying

Try the following basic queries to get started:

Current User

query {
  currentUser {
    id
    givenName
    familyName
    email
  }
}

will return something similar to

{
  "data": {
    "currentUser": {
      "id": "79c74139-22f7-4f35-b6bc-9f15802a4720",
      "givenName": "Alice",
      "familyName": "McCloud",
      "email": "alice@screencloud.com"
    }
  }
}

Current User with teams and their screens

query {
  currentUser {
    email
    teamsByUserId {
      nodes {
        name
        screensByTeamId {
          nodes {
            name
            id
            screenGroupId
          }
        }
      }
    }
  }
}

will return something similar to

{
  "data": {
    "currentUser": {
      "email": "alice@screencloud.com",
      "teamsByUserId": {
        "nodes": [
          {
            "name": "_default_team",
            "screensByTeamId": {
              "nodes": [
                {
                  "name": "ScreenCloud Player",
                  "id": "7f697859-a0cb-4bba-9581-35ba02759086",
                  "screenGroupId": "1e6836b6-009e-47b1-ba2a-48c16eb1ee4a"
                }
              ]
            }
          }
        ]
      }
    }
  }
}

Pair a screen

mutation {
  pairScreen(input: {
    pairing: {
      code: "<screen-pairing-code>"
    }
    screenGroupId: "<target-screen-group-id>"
  })
  { 
    screen {
      device
      name
    }
  }
}

Will pair a screen to your organisation and add it to the chose screenGroup. It will then return that screens device and name properties.

Change a screens channel


mutation {
  setScreenChannel(input: {
    screenId: "<target-screen-id>",
    channelId: "<target-channel-id>"
  })
  {
    screen {
      channelsByScreenId { 
        nodes {
          id
          name
        }
      }
    }
  }
}

Get all channels

query  {
  allChannels {
    nodes {
      id
      name
    }
  }
}

Postman, CURL and others

The actual query needs a JSON envelope similar to:

{
  "operationName":"pairScreen",
  "query":"mutation pairScreen{ pairScreen(input: { pairing: { code: \"123123\" } screenGroupId: \"123123\" }) { screen { device name id }}}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment