From 81d01fb5cbcdb643ea5adf55f82ff6c99a2d40ee Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Wed, 6 Feb 2019 23:30:27 -0700 Subject: [PATCH] add searchCompanyByName --- 3.0/connectwise/company.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/3.0/connectwise/company.go b/3.0/connectwise/company.go index 8efa3ac..b12601c 100644 --- a/3.0/connectwise/company.go +++ b/3.0/connectwise/company.go @@ -583,3 +583,22 @@ func (cw *Site) NewContactCommunication(communication *ContactCommunication) (*C return communication, nil } + +func (cw *Site) SearchCompanyByName(name string) (*[]Company, error) { + req := cw.NewRequest("/company/companies", "GET", nil) + req.URLValues.Add("conditions", "name contains \""+name+"\"") + req.URLValues.Add("pageSize", "40") + req.URLValues.Add("fields", "name") + err := req.Do() + if err != nil { + return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err) + } + + companies := &[]Company{} + err = json.Unmarshal(req.Body, companies) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal body into struct: %s", err) + } + + return companies, nil +}