Playing with G Suite MDM mobile device data using Go

Our desktop support & G Suite admin folks needed a simple, fast command-line tool to query basic info about our company’s mobile devices (which are all managed using G Suite’s built-in MDM).

So I wrote one.

Since this tool needs to be run via command-line, it can’t use any interactive or browser-based authentication, so we need to use a service account for authentication.

Pre-requisites (GCP & G Suite):

  • Create a service account in your G Suite domain (Google Cloud Console –> IAM & Admin –> Service Accounts)
  • Be sure that you have checked the “Enable G Suite Domain-wide Delegation” box as this will give your new service account the appropriate permissions to query the G Suite Admin API
  • Download the service account JSON credentials file. Open it up and find the client_id. Make a note of it!
  • Now we need to authorize the client_id of your service account for the necessary API scopes. In the Admin Console for your G Suite domain (Admin Console –> Security –> Advanced Settings –> Authentication –> Manage API Client Access), add your client_id in the “Client Name” box, and add
    in the “One or more API scopes” box
  • Click the “Authorize” button when you’re finished

Pre-requisites (Go)
You’ll need to “go get” a few packages:

  • go get -u
  • go get -u
  • go get -u

Pre-requisites (Environment Variables)
Because it’s never good to store runtime configuration within code, you’ll notice that the code references several environment variables. Setup them up to suit your preference but something like this will do:

export GSUITE_COMPANYID="A01234567"
export SVC_ACCOUNT_CREDS_JSON="/home/rickt/dev/adminsdk/golang/creds.json

And finally, the code
Gist URL:

a simple slack weather bot

it’s been really hot in Los Angeles recently, and i realised i was switching back to my web browser from the Slack app to find out the current temperature downstairs an awful lot before leaving the office.

i realised that a /weather command would far more efficient. say hello to slack-weather-bot.

a simple golang backend that take a request for /weather?zip=NNNNN and then posts a quick one-liner of current conditions back to you on Slack. enjoy.

slack useragent checker

are you curious if your [corporate] Slack users are logging into Slack using a Slack desktop or mobile app, or if they’re just using the Slack webpage? here’s some example code to call the slack team.accessLogs API to output which of your Slack users are not using a desktop or mobile Slack app.

Slack Translation Bot

stable release of Slack Translator Bot.

what is Slack Translator Bot? the [as-is demo] code gets you get a couple of Slack /slash commands that let you translate from English to Japanese, and vice-versa.

below screenshot shows example response to a Slack user wanting to translate “the rain in spain falls mainly on the plane” by typing:


within slack:



  • you get a google translate api key
  • you deploy a go backend app to Google Appengine that responds to
  • a couple of custom Slack /slash commands that you create in Slack
  • you profit


Slack Team Directory Bot

stable release of Slack Team Directory Bot.

what is Slack Team Directory Bot? you get a Slack /slash command that lets you search your Slack Team Directory quick as a flash.

below screenshot shows example response to a Slack trying to find someone in your accounting department by typing:


within slack:



  • you deploy a go backend app to Google Appengine that responds to…
  • a custom Slack /slash command that you create in Slack

UPDATED: golang code to query GA data via the Google Core Reporting API using two-legged service account Google OAuth2 authentication

i’ve updated my example Golang code that authenticates with the Core Reporting API using service account OAuth2 (two-legged) authentication to use the newly updated library.

my previous post & full explanation of service account pre-reqs/setup:

full code:

have fun!

drop me a line or say hello on twitter if any questions.


stable release of my modified-for Google Appengine fork of i have this working in production on several Appengine-hosted /slash commands & bots.

the TL;DR on my modifications:


Slack Timebot

stable release of Slack Timebot.

what is Slack Timebot? at work, i very often have to know what time it is in the following regions:

  • PST
  • UTC
  • JST

so i wrote a mini go backend app that i threw into a free Google Appengine app and so now i can get the time instantly by using any of these new Slack /slash commands:

  • /time (PST)
  • /utctime (UTC)
  • /japantime (JST)


  • you deploy a go backend app to Google Appengine that responds to
  • a couple of custom Slack /slash commands that you create in Slack