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

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