// RequestSalesReport will request a report from Redcat
RequestSalesReport will request a report from Redcat
// RequestSalesReport will request a report from Redcat
func (v *Redcat) RequestSalesReport(request ReportRequest) (*ReportResult, error) {
	urlStr := v.BaseURL + salesByURL
	fmt.Println("Connecting to redcat", urlStr)
	body, err := json.Marshal(request)
	if err != nil {
		return nil, err
	}
	fmt.Println("Sending body", string(body))
	client := &http.Client{}
	r, err := http.NewRequest("POST", urlStr, bytes.NewBuffer(body))
	if err != nil {
		return nil, err
	}
	r.Header = http.Header(make(map[string][]string))
	r.Header.Set(authHeader, v.accessToken)
	r.Header.Set("Content-Type", "application/json")
	res, err := client.Do(r)
	if err != nil {
		return nil, err
	}
	if res.StatusCode == 200 {
		rawResBody, err := ioutil.ReadAll(res.Body)
		if err != nil {
			return nil, err
		}
		var resp ReportResult
		err = json.Unmarshal(rawResBody, &resp)
		if err != nil {
			return nil, err
		}
		return &resp, nil
	}
	return nil, fmt.Errorf("Failed to get Redcat Sales Report %s", res.Status)
}
func ( v * Redcat ) RequestSalesReport ( request ReportRequest ) ( * ReportResult , error ) { urlStr := v . BaseURL + salesByURL fmt . Println ( " " , urlStr ) body , err := json . Marshal ( request ) if err != nil { return nil , err } fmt . Println ( " " , string ( body ) ) client := & http . Client { } r , err := http . NewRequest ( " " , urlStr , bytes . NewBuffer ( body ) ) if err != nil { return nil , err } r . Header = http . Header ( make ( map [ string ] [ ] string ) ) r . Header . Set ( authHeader , v . accessToken ) r . Header . Set ( " " , " " ) res , err := client . Do ( r ) if err != nil { return nil , err } if res . StatusCode == 200 { rawResBody , err := ioutil . ReadAll ( res . Body ) if err != nil { return nil , err } var resp ReportResult err = json . Unmarshal ( rawResBody , & resp ) if err != nil { return nil , err } return & resp , nil } return nil , fmt . Errorf ( " " , res . Status ) }
RequestSalesReport will request a report from Redcat
RequestSalesReport will request a report from Redcat
//fmt.Println("Got response", string(rawResBody))