diff --git a/team.go b/team.go index 9aac633..7a6614d 100644 --- a/team.go +++ b/team.go @@ -79,18 +79,31 @@ func (c *Client) Team(id int64) (*Team, error) { // AddTeam makes a new team // email arg is an optional value. // If you don't want to set email, please set "" (empty string). -func (c *Client) AddTeam(name string, email string) error { +// When team creation is successful, returns the team id +func (c *Client) AddTeam(name string, email string) (int64, error) { + id := int64(0) path := fmt.Sprintf("/api/teams") + team := Team{ Name: name, Email: email, } data, err := json.Marshal(team) if err != nil { - return err + return id, err } - return c.request("POST", path, nil, bytes.NewBuffer(data), nil) + tmp := struct { + Id int64 `json:"teamId"` + }{} + + err = c.request("POST", path, nil, bytes.NewBuffer(data), &tmp) + + if err != nil { + return id, err + } + + return tmp.Id, err } // UpdateTeam updates a Grafana team. diff --git a/teams_test.go b/teams_test.go index 88b7249..2d43e50 100644 --- a/teams_test.go +++ b/teams_test.go @@ -158,10 +158,13 @@ func TestAddTeam(t *testing.T) { name := "TestTeam" email := "" - err := client.AddTeam(name, email) + id, err := client.AddTeam(name, email) if err != nil { t.Error(err) } + if id == 0 { + t.Error("AddTeam returned an invalid id.") + } } func TestUpdateTeam(t *testing.T) {