github.com/schmorrison/Zoho@v1.1.4/crm/roles.go (about) 1 package crm 2 3 import ( 4 "fmt" 5 6 zoho "github.com/schmorrison/Zoho" 7 ) 8 9 // GetRoles will return the list of roles in this CRM organization 10 // https://www.zoho.com/crm/help/api/v2/#Roles-APIs 11 func (c *API) GetRoles() (data RolesResponse, err error) { 12 endpoint := zoho.Endpoint{ 13 Name: "roles", 14 URL: fmt.Sprintf("https://www.zohoapis.%s/crm/v2/settings/roles", c.ZohoTLD), 15 Method: zoho.HTTPGet, 16 ResponseData: &RolesResponse{}, 17 } 18 19 err = c.Zoho.HTTPRequest(&endpoint) 20 if err != nil { 21 return RolesResponse{}, fmt.Errorf("Failed to retrieve roles: %s", err) 22 } 23 24 if v, ok := endpoint.ResponseData.(*RolesResponse); ok { 25 return *v, nil 26 } 27 28 return RolesResponse{}, fmt.Errorf("Data retrieved was not 'RolesResponse'") 29 } 30 31 // GetRole will return the role specified by the id 32 // https://www.zoho.com/crm/help/api/v2/#get-single-role-data 33 func (c *API) GetRole(id string) (data RolesResponse, err error) { 34 endpoint := zoho.Endpoint{ 35 Name: "roles", 36 URL: fmt.Sprintf( 37 "https://www.zohoapis.%s/crm/v2/settings/roles/%s", 38 c.ZohoTLD, 39 id, 40 ), 41 Method: zoho.HTTPGet, 42 ResponseData: &RolesResponse{}, 43 } 44 45 err = c.Zoho.HTTPRequest(&endpoint) 46 if err != nil { 47 return RolesResponse{}, fmt.Errorf("Failed to retrieve role (%s): %s", id, err) 48 } 49 50 if v, ok := endpoint.ResponseData.(*RolesResponse); ok { 51 return *v, nil 52 } 53 54 return RolesResponse{}, fmt.Errorf("Data retrieved was not 'RolesResponse'") 55 } 56 57 // RolesResponse is the data returned by GetRoles and GetRole 58 type RolesResponse struct { 59 Roles []struct { 60 DisplayLabel string `json:"display_label,omitempty"` 61 Name string `json:"name,omitempty"` 62 ID string `json:"id,omitempty"` 63 ReportingTo string `json:"reporting_to,omitempty"` 64 AdminUser bool `json:"admin_user,omitempty"` 65 } `json:"roles,omitempty"` 66 }