github.com/schmorrison/Zoho@v1.1.4/crm/users.go (about)

     1  package crm
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  // GetUsers will return the list of users in the CRM organization. The list can be filtered using the
    10  // 'kind' parameter
    11  // https://www.zoho.com/crm/help/api/v2/#Users-APIs
    12  func (c *API) GetUsers(kind UserType) (data UsersResponse, err error) {
    13  	endpoint := zoho.Endpoint{
    14  		Name:         "users",
    15  		URL:          fmt.Sprintf("https://www.zohoapis.%s/crm/v2/users", c.ZohoTLD),
    16  		Method:       zoho.HTTPGet,
    17  		ResponseData: &UsersResponse{},
    18  		URLParameters: map[string]zoho.Parameter{
    19  			"type": kind,
    20  		},
    21  	}
    22  
    23  	err = c.Zoho.HTTPRequest(&endpoint)
    24  	if err != nil {
    25  		return UsersResponse{}, fmt.Errorf("Failed to retrieve users: %s", err)
    26  	}
    27  
    28  	if v, ok := endpoint.ResponseData.(*UsersResponse); ok {
    29  		return *v, nil
    30  	}
    31  
    32  	return UsersResponse{}, fmt.Errorf("Data retrieved was not 'UsersResponse'")
    33  }
    34  
    35  // GetUser will return the user specified by id
    36  // https://www.zoho.com/crm/help/api/v2/#get-single-user-data
    37  func (c *API) GetUser(id string) (data UsersResponse, err error) {
    38  	endpoint := zoho.Endpoint{
    39  		Name:         "users",
    40  		URL:          fmt.Sprintf("https://www.zohoapis.%s/crm/v2/users/%s", c.ZohoTLD, id),
    41  		Method:       zoho.HTTPGet,
    42  		ResponseData: &UsersResponse{},
    43  	}
    44  
    45  	err = c.Zoho.HTTPRequest(&endpoint)
    46  	if err != nil {
    47  		return UsersResponse{}, fmt.Errorf("Failed to retrieve user (%s): %s", id, err)
    48  	}
    49  
    50  	if v, ok := endpoint.ResponseData.(*UsersResponse); ok {
    51  		return *v, nil
    52  	}
    53  
    54  	return UsersResponse{}, fmt.Errorf("Data retrieved was not 'UsersResponse'")
    55  }
    56  
    57  // UserType is the 'kind' parameter in the GetUsers function
    58  type UserType = zoho.Parameter
    59  
    60  const (
    61  	// None - Do not filter the Users list
    62  	None UserType = ""
    63  	// AllUsers - To list all users in your organization (both active and inactive users)
    64  	AllUsers UserType = "AllUsers"
    65  	// ActiveUsers - To get the list of all Active Users
    66  	ActiveUsers UserType = "ActiveUsers"
    67  	// DeactiveUsers - To get the list of all users who were deactivated
    68  	DeactiveUsers UserType = "DeactiveUsers"
    69  	// ConfirmedUsers - To get the list of confirmed users
    70  	ConfirmedUsers UserType = "ConfirmedUsers"
    71  	// NotConfirmedUsers - To get the list of non-confirmed users
    72  	NotConfirmedUsers UserType = "NotConfirmedUsers"
    73  	// DeletedUsers - To get the list of deleted users
    74  	DeletedUsers UserType = "DeletedUsers"
    75  	// ActiveConfirmedUsers - To get the list of active users who are also confirmed
    76  	ActiveConfirmedUsers UserType = "ActiveConfirmedUsers"
    77  	// AdminUsers - To get the list of admin users.
    78  	AdminUsers UserType = "AdminUsers"
    79  	// ActiveConfirmedAdmins - To get the list of active users with the administrative privileges and are also confirmed
    80  	ActiveConfirmedAdmins UserType = "ActiveConfirmedAdmins"
    81  	// CurrentUser - To get the list of current CRM users
    82  	CurrentUser UserType = "CurrentUser"
    83  )
    84  
    85  // UsersResponse is the data returned by GetUsers and GetUser
    86  type UsersResponse struct {
    87  	Users []struct {
    88  		Country string `json:"country,omitempty"`
    89  		Role    struct {
    90  			Name string `json:"name,omitempty"`
    91  			ID   string `json:"id,omitempty"`
    92  		} `json:"role,omitempty"`
    93  		City       string `json:"city,omitempty"`
    94  		Language   string `json:"language,omitempty"`
    95  		Locale     string `json:"locale,omitempty"`
    96  		ModifiedBy struct {
    97  			Name string `json:"name,omitempty"`
    98  			ID   string `json:"id,omitempty"`
    99  		} `json:"Modified_By,omitempty"`
   100  		Street        string `json:"street,omitempty"`
   101  		Currency      string `json:"Currency,omitempty"`
   102  		Alias         string `json:"alias,omitempty"`
   103  		ID            string `json:"id,omitempty"`
   104  		State         string `json:"state,omitempty"`
   105  		Fax           string `json:"fax,omitempty"`
   106  		CountryLocale string `json:"country_locale,omitempty"`
   107  		FirstName     string `json:"first_name,omitempty"`
   108  		Email         string `json:"email,omitempty"`
   109  		ReportingTo   string `json:"Reporting_To,omitempty"`
   110  		Zip           string `json:"zip,omitempty"`
   111  		CreatedTime   string `json:"created_time,omitempty"`
   112  		ModifiedTime  string `json:"modified_time,omitempty"`
   113  		Website       string `json:"website,omitempty"`
   114  		TimeFormat    string `json:"time_format,omitempty"`
   115  		Offset        int64  `json:"offset,omitempty"`
   116  		Profile       struct {
   117  			Name string `json:"name,omitempty"`
   118  			ID   string `json:"id,omitempty"`
   119  		} `json:"profile,omitempty"`
   120  		Mobile    string `json:"mobile,omitempty"`
   121  		LastName  string `json:"last_name,omitempty"`
   122  		CreatedBy struct {
   123  			Name string `json:"name,omitempty"`
   124  			ID   string `json:"id,omitempty"`
   125  		} `json:"created_by,omitempty"`
   126  		Zuid        string `json:"zuid,omitempty"`
   127  		Confirm     bool   `json:"confirm,omitempty"`
   128  		FullName    string `json:"full_name,omitempty"`
   129  		Territories []struct {
   130  			Manager bool   `json:"manager,omitempty"`
   131  			Name    string `json:"name,omitempty"`
   132  			ID      string `json:"id,omitempty"`
   133  		} `json:"territories,omitempty"`
   134  		Phone         string `json:"phone,omitempty"`
   135  		Dob           string `json:"dob,omitempty"`
   136  		DateFormat    string `json:"date_format,omitempty"`
   137  		Status        string `json:"status,omitempty"`
   138  		CustomizeInfo struct {
   139  			NotesDesc       string `json:"notes_desc,omitempty"`
   140  			ShowRightPanel  bool   `json:"show_right_panel,omitempty"`
   141  			BcView          string `json:"bc_view,omitempty"`
   142  			ShowHome        bool   `json:"show_home,omitempty"`
   143  			UnpinRecentItem bool   `json:"unpin_recent_item,omitempty"`
   144  		} `json:"customize_info,omitempty,omitempty"`
   145  		Signature           string `json:"signature,omitempty,omitempty"`
   146  		NameFormat          string `json:"name_format,omitempty,omitempty"`
   147  		PersonalAccount     bool   `json:"personal_account,omitempty,omitempty"`
   148  		NtcNotificationType []int  `json:"ntc_notification_type,omitempty,omitempty"`
   149  		DefaultTabGroup     string `json:"default_tab_group,omitempty,omitempty"`
   150  		Theme               struct {
   151  			NormalTab struct {
   152  				FontColor  string `json:"font_color,omitempty"`
   153  				Background string `json:"background,omitempty"`
   154  			} `json:"normal_tab,omitempty"`
   155  			SelectedTab struct {
   156  				FontColor  string `json:"font_color,omitempty"`
   157  				Background string `json:"background,omitempty"`
   158  			} `json:"selected_tab,omitempty"`
   159  			NewBackground string `json:"new_background,omitempty"`
   160  			Background    string `json:"background,omitempty"`
   161  			Screen        string `json:"screen,omitempty"`
   162  			Type          string `json:"type,omitempty"`
   163  		} `json:"theme,omitempty,omitempty"`
   164  		TelephonyEnabled bool   `json:"telephony_enabled,omitempty,omitempty"`
   165  		ImapStatus       bool   `json:"imap_status,omitempty,omitempty"`
   166  		DecimalSeparator string `json:"decimal_separator,omitempty,omitempty"`
   167  		TimeZone         string `json:"time_zone,omitempty"`
   168  		RtlEnabled       bool   `json:"rtl_enabled,omitempty,omitempty"`
   169  		NtcEnabled       bool   `json:"ntc_enabled,omitempty,omitempty"`
   170  	} `json:"users,omitempty"`
   171  	Info PageInfo `json:"info,omitempty"`
   172  }