Add CompanyCount method and Count struct to hold return data
This commit is contained in:
parent
d2ec87e7ca
commit
7e94afac9c
@ -145,6 +145,23 @@ type Company struct {
|
||||
} `json:"customFields"`
|
||||
}
|
||||
|
||||
//CompanyCount returns the number of companies in ConnectWise
|
||||
func (cw *Site) CompanyCount() (int, error) {
|
||||
req := NewRequest(cw, "/company/companies/count", "GET", nil)
|
||||
err := req.Do()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("request failed for %s: %s", req.RestAction, err)
|
||||
}
|
||||
|
||||
count := &Count{}
|
||||
err = json.Unmarshal(req.Body, count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to unmarshal body into struct: %s", err)
|
||||
}
|
||||
|
||||
return count.Count, nil
|
||||
}
|
||||
|
||||
//GetCompanyByName expects an exact match, perhaps an improvement could be made to support wildcard characters.
|
||||
//Will return a pointer to a slice of Company's.
|
||||
func (cw *Site) GetCompanyByName(companyName string) (*[]Company, error) {
|
||||
|
@ -11,6 +11,10 @@ type Site struct {
|
||||
Auth string
|
||||
}
|
||||
|
||||
type Count struct {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
//NewSite returns a pointer to a ConnectwiseSite struct with the site and auth string available for use in API requests
|
||||
func NewSite(site string, publicKey string, privateKey string, company string) *Site {
|
||||
//The auth string must be formatted in this way when used in requests to the API
|
||||
|
Loading…
Reference in New Issue
Block a user