diff --git a/app/controllers/projects/mattermost_controller.rb b/app/controllers/projects/mattermost_controller.rb
index f50f921c7cf1cb596c6ba5690844312e15cd5c58..f04189c8775e384ff64dce70eadc02bf84462c8a 100644
--- a/app/controllers/projects/mattermost_controller.rb
+++ b/app/controllers/projects/mattermost_controller.rb
@@ -32,16 +32,13 @@ class Projects::MattermostController < Projects::ApplicationController
   end
 
   def teams
-    # Mocking for frontend development
-    @teams = [{"id"=>"qz8gdr1fopncueb8n9on8ohk3h", "create_at"=>1479992105904, "update_at"=>1479992105904, "delete_at"=>0, "display_name"=>"chatops", "name"=>"chatops", "email"=>"admin@example.com", "type"=>"O", "company_name"=>"", "allowed_domains"=>"", "invite_id"=>"gthxi47gj7rxtcx6zama63zd1w", "allow_open_invite"=>false}]
-
-    #  @teams =
-    #       begin
-    #         Mattermost::Mattermost.new(Gitlab.config.mattermost.host, current_user).with_session do
-    #          Mattermost::Team.all
-    #        end
-    #      rescue Mattermost::NoSessionError
-    #        @teams = []
-    #      end
+    @teams =
+      begin
+        Mattermost::Mattermost.new(Gitlab.config.mattermost.host, current_user).with_session do
+          Mattermost::Team.team_admin
+        end
+      rescue Mattermost::NoSessionError
+        []
+      end
   end
 end
diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb
index c0e8e1a9324f25703e53dc00e39e0cfdf3f43c67..e07cc0e4077a8a0a79e9243c4130d0d3e2d53c3f 100644
--- a/app/models/project_services/mattermost_slash_commands_service.rb
+++ b/app/models/project_services/mattermost_slash_commands_service.rb
@@ -25,10 +25,6 @@ class MattermostSlashCommandsService < ChatService
     ]
   end
 
-  def auto_config?
-    Gitlab.config.mattermost.enabled
-  end
-
   def configure(host, current_user, params)
     token = Mattermost::Mattermost.new(host, current_user).with_session do
       Mattermost::Commands.create(params[:team_id],
diff --git a/app/models/service.rb b/app/models/service.rb
index 9004d9caa1974d2e83eaf79dcd4c4d3e66b38832..e49a8fa29040fa6d61c895bc10eab5192e9ed1d6 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -54,10 +54,6 @@ class Service < ActiveRecord::Base
     template
   end
 
-  def auto_config?
-    false
-  end
-
   def category
     read_attribute(:category).to_sym
   end
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb
index e159458a788f6ecfe91e1ca4733855d2caa61074..b6446935eb6ecd01720ddb8d6376a44af1149477 100644
--- a/lib/mattermost/command.rb
+++ b/lib/mattermost/command.rb
@@ -1,7 +1,7 @@
 module Mattermost
-  class Command
+  class Command < Session
     def self.all(team_id)
-      Mattermost::Mattermost.get("/teams/#{team_id}/commands/list_team_commands")
+      get("/teams/#{team_id}/commands/list_team_commands").parsed_response
     end
 
     # params should be a hash, which supplies _at least_:
@@ -9,18 +9,20 @@ module Mattermost
     # - url => What is the URL to trigger here?
     # - icon_url => Supply a link to the icon
     def self.create(team_id, params)
-      params = {
+      command = {
         auto_complete: true,
         auto_complete_desc: 'List all available commands',
         auto_complete_hint: '[help]',
         description: 'Perform common operations on GitLab',
         display_name: 'GitLab',
         method: 'P',
-        user_name: 'GitLab'
-      }..merge(params)
+        user_name: 'GitLab',
+        trigger: 'gitlab',
+      }.merge(params)
 
-      Mattermost::Mattermost.post( "/teams/#{team_id}/commands/create", params.to_json).
-        parsed_response['token']
+      response = post( "/teams/#{team_id}/commands/create", body: command.to_json)
+
+      response.parsed_response['token']
     end
   end
 end
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index cc4cb1f4f1218a7a0fedd60b42b45127d1a9174c..15bf95a38c94bb354ab2ee705142620dede0ebb1 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -65,6 +65,7 @@ module Mattermost
       return unless token_uri
 
       self.class.headers("Cookie" => "MMAUTHTOKEN=#{request_token}")
+      self.class.headers("X-Requested-With" => 'XMLHttpRequest')
 
       request_token
     end
@@ -106,7 +107,6 @@ module Mattermost
 
     def normalize_uri(uri)
       uri << '/' unless uri.end_with?('/')
-
       uri << 'api/v3'
     end
   end
diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb
index 76e238a866ea1855c04210750473f0f22f2c2801..54d029cb02295b59b00dc6dccc93ff521ded96a5 100644
--- a/lib/mattermost/team.rb
+++ b/lib/mattermost/team.rb
@@ -1,10 +1,17 @@
 module Mattermost
-  class Team < Mattermost
-    # After normalization this returns an array of hashes
-    #
-    # [{"id"=>"paf573pj9t81urupw3fanozeda", "display_name"=>"my team", <snip>}]
-    def self.all
-      @all_teams ||= get('/teams/all').parsed_response.values
+  class Team < Session
+    def self.team_admin
+      body = get('/users/initial_load').parsed_response
+
+      return [] unless body['team_members']
+
+      team_ids = body['team_members'].map do |team|
+        team['team_id'] if team['roles'].split.include?('team_admin')
+      end.compact
+
+      body['teams'].select do |team|
+        team_ids.include?(team['id'])
+      end
     end
   end
 end
diff --git a/spec/lib/mattermost/team_spec.rb b/spec/lib/mattermost/team_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..a3b0831659f8a0aaaa2cc37ad30de643524d11fd
--- /dev/null
+++ b/spec/lib/mattermost/team_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe Mattermost::Team do
+  let(:session) { Mattermost::Session.new('http://localhost:8065/', nil) }
+
+  describe '.all' do
+    let(:result)  { {id: 'abc', display_name: 'team'} }
+    before do
+      WebMock.stub_request(:get, 'http://localhost:8065/api/v3/teams/all').
+        and_return({ abc: result }.to_json)
+    end
+
+    xit 'gets the teams' do
+      allow(session).to receive(:with_session) { yield }
+
+      expect(described_class.all).to eq(result)
+    end
+  end
+end