Updated file layout to match CW API documentation
This commit is contained in:
parent
8adc3a69a1
commit
a66ba7ca89
151
3.0/connectwise/finance.go
Normal file
151
3.0/connectwise/finance.go
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
package connectwise
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Agreements []Agreement
|
||||||
|
|
||||||
|
type Agreement struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info struct {
|
||||||
|
TypeHref string `json:"type_href"`
|
||||||
|
} `json:"_info"`
|
||||||
|
} `json:"type"`
|
||||||
|
Company struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Identifier string `json:"identifier"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info struct {
|
||||||
|
CompanyHref string `json:"company_href"`
|
||||||
|
} `json:"_info"`
|
||||||
|
} `json:"company"`
|
||||||
|
Contact struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info struct {
|
||||||
|
ContactHref string `json:"contact_href"`
|
||||||
|
} `json:"_info"`
|
||||||
|
} `json:"contact"`
|
||||||
|
CustomerPO string `json:"customerPO"`
|
||||||
|
LocationID int `json:"locationId"`
|
||||||
|
BusinessUnitID int `json:"businessUnitId"`
|
||||||
|
RestrictLocationFlag bool `json:"restrictLocationFlag"`
|
||||||
|
RestrictDepartmentFlag bool `json:"restrictDepartmentFlag"`
|
||||||
|
StartDate string `json:"startDate"`
|
||||||
|
EndDate string `json:"endDate,omitempty"`
|
||||||
|
NoEndingDateFlag bool `json:"noEndingDateFlag"`
|
||||||
|
CancelledFlag bool `json:"cancelledFlag"`
|
||||||
|
ReasonCancelled string `json:"reasonCancelled"`
|
||||||
|
WorkOrder string `json:"workOrder"`
|
||||||
|
InternalNotes string `json:"internalNotes"`
|
||||||
|
ApplicationUnits string `json:"applicationUnits"`
|
||||||
|
ApplicationLimit float64 `json:"applicationLimit"`
|
||||||
|
ApplicationCycle string `json:"applicationCycle,omitempty"`
|
||||||
|
ApplicationUnlimitedFlag bool `json:"applicationUnlimitedFlag"`
|
||||||
|
OneTimeFlag bool `json:"oneTimeFlag"`
|
||||||
|
CoverAgreementTime bool `json:"coverAgreementTime"`
|
||||||
|
CoverAgreementProduct bool `json:"coverAgreementProduct"`
|
||||||
|
CoverAgreementExpense bool `json:"coverAgreementExpense"`
|
||||||
|
CoverSalesTax bool `json:"coverSalesTax"`
|
||||||
|
CarryOverUnused bool `json:"carryOverUnused"`
|
||||||
|
AllowOverruns bool `json:"allowOverruns"`
|
||||||
|
ExpiredDays int `json:"expiredDays,omitempty"`
|
||||||
|
Limit int `json:"limit,omitempty"`
|
||||||
|
ExpireWhenZero bool `json:"expireWhenZero"`
|
||||||
|
ChargeToFirm bool `json:"chargeToFirm"`
|
||||||
|
EmployeeCompRate string `json:"employeeCompRate"`
|
||||||
|
CompHourlyRate float64 `json:"compHourlyRate"`
|
||||||
|
CompLimitAmount float64 `json:"compLimitAmount"`
|
||||||
|
BillCycleID int `json:"billCycleId"`
|
||||||
|
BillOneTimeFlag bool `json:"billOneTimeFlag"`
|
||||||
|
BillTermsID int `json:"billTermsId"`
|
||||||
|
InvoicingCycle string `json:"invoicingCycle"`
|
||||||
|
BillAmount float64 `json:"billAmount"`
|
||||||
|
Taxable bool `json:"taxable"`
|
||||||
|
ProrateFirstBill float64 `json:"prorateFirstBill,omitempty"`
|
||||||
|
BillStartDate string `json:"billStartDate"`
|
||||||
|
TaxCodeID int `json:"taxCodeId"`
|
||||||
|
RestrictDownPayment bool `json:"restrictDownPayment"`
|
||||||
|
ProrateFlag bool `json:"prorateFlag"`
|
||||||
|
InvoiceDescription string `json:"invoiceDescription"`
|
||||||
|
TopComment bool `json:"topComment"`
|
||||||
|
BottomComment bool `json:"bottomComment"`
|
||||||
|
BillTime string `json:"billTime"`
|
||||||
|
BillExpenses string `json:"billExpenses"`
|
||||||
|
BillProducts string `json:"billProducts"`
|
||||||
|
BillableTimeInvoice bool `json:"billableTimeInvoice"`
|
||||||
|
BillableExpenseInvoice bool `json:"billableExpenseInvoice"`
|
||||||
|
BillableProductInvoice bool `json:"billableProductInvoice"`
|
||||||
|
Currency struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Symbol string `json:"symbol"`
|
||||||
|
IsoCode string `json:"isoCode"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info struct {
|
||||||
|
CurrencyHref string `json:"currency_href"`
|
||||||
|
} `json:"_info"`
|
||||||
|
} `json:"currency"`
|
||||||
|
Info struct {
|
||||||
|
LastUpdated string `json:"lastUpdated"`
|
||||||
|
UpdatedBy string `json:"updatedBy"`
|
||||||
|
} `json:"_info"`
|
||||||
|
DateCancelled string `json:"dateCancelled,omitempty"`
|
||||||
|
SLAID int `json:"slaId,omitempty"`
|
||||||
|
EmployeeCompNotExceed string `json:"employeeCompNotExceed,omitempty"`
|
||||||
|
BillToCompany struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Identifier string `json:"identifier"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info struct {
|
||||||
|
CompanyHref string `json:"company_href"`
|
||||||
|
} `json:"_info"`
|
||||||
|
} `json:"billToCompany,omitempty"`
|
||||||
|
BillToSite struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info struct {
|
||||||
|
SiteHref string `json:"site_href"`
|
||||||
|
} `json:"_info"`
|
||||||
|
} `json:"billToSite,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAgreements(site *ConnectwiseSite) *Agreements {
|
||||||
|
|
||||||
|
agreements := Agreements{}
|
||||||
|
|
||||||
|
//Build the request URL
|
||||||
|
var Url *url.URL
|
||||||
|
Url, err := url.Parse(site.Site)
|
||||||
|
check(err)
|
||||||
|
Url.Path += "/finance/agreements"
|
||||||
|
parameters := url.Values{}
|
||||||
|
parameters.Add("conditions", "billCycleId=2")
|
||||||
|
parameters.Add("pageSize", "1000")
|
||||||
|
Url.RawQuery = parameters.Encode()
|
||||||
|
|
||||||
|
body := GetRequest(site, Url)
|
||||||
|
check(json.Unmarshal(body, &agreements))
|
||||||
|
|
||||||
|
return &agreements
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetBillingCycles(site *ConnectwiseSite) {
|
||||||
|
|
||||||
|
//Build the request URL
|
||||||
|
var Url *url.URL
|
||||||
|
Url, err := url.Parse(site.Site)
|
||||||
|
check(err)
|
||||||
|
Url.Path += "/finance/billingCycles"
|
||||||
|
|
||||||
|
body := GetRequest(site, Url)
|
||||||
|
fmt.Print(string(body))
|
||||||
|
// check(json.Unmarshal(body, &ticket))
|
||||||
|
}
|
@ -12,7 +12,7 @@ import (
|
|||||||
//Checks for HTTP errors, and if all looks good, returns the body of the HTTP response as a byte slice
|
//Checks for HTTP errors, and if all looks good, returns the body of the HTTP response as a byte slice
|
||||||
//TBD: Needs to accept 201 and 204 (returned for Create and Delete operations)
|
//TBD: Needs to accept 201 and 204 (returned for Create and Delete operations)
|
||||||
func getHTTPResponseBody(resp *http.Response) []byte {
|
func getHTTPResponseBody(resp *http.Response) []byte {
|
||||||
if resp.StatusCode != http.StatusOK {
|
if (resp.StatusCode != http.StatusOK) && (resp.StatusCode != http.StatusCreated) && (resp.StatusCode != http.StatusNoContent) {
|
||||||
out := fmt.Sprintf("CW API returned HTTP Status Code %s\n%s", resp.Status, resp.Body)
|
out := fmt.Sprintf("CW API returned HTTP Status Code %s\n%s", resp.Status, resp.Body)
|
||||||
log.Fatal(out)
|
log.Fatal(out)
|
||||||
return make([]byte, 0)
|
return make([]byte, 0)
|
||||||
|
@ -3,7 +3,6 @@ package connectwise
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -175,6 +174,15 @@ type Ticket struct {
|
|||||||
ContactPhoneExtension string `json:"contactPhoneExtension,omitempty"`
|
ContactPhoneExtension string `json:"contactPhoneExtension,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TBD: For some reason the Info struct contained in TimeEntryReference does get data when the JSON is unmarshaled into this struct. The ID works fine
|
||||||
|
type TimeEntryReference struct {
|
||||||
|
ID int
|
||||||
|
Info struct {
|
||||||
|
Notes string
|
||||||
|
TimeHref string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetTicketByID(site *ConnectwiseSite, ticketID int) *Ticket {
|
func GetTicketByID(site *ConnectwiseSite, ticketID int) *Ticket {
|
||||||
|
|
||||||
ticket := Ticket{}
|
ticket := Ticket{}
|
||||||
@ -185,18 +193,23 @@ func GetTicketByID(site *ConnectwiseSite, ticketID int) *Ticket {
|
|||||||
check(err)
|
check(err)
|
||||||
Url.Path += fmt.Sprintf("/service/tickets/%d", ticketID)
|
Url.Path += fmt.Sprintf("/service/tickets/%d", ticketID)
|
||||||
|
|
||||||
//Build and make the request
|
body := GetRequest(site, Url)
|
||||||
client := &http.Client{}
|
|
||||||
req, err := http.NewRequest("GET", Url.String(), nil)
|
|
||||||
check(err)
|
|
||||||
req.Header.Set("Authorization", site.Auth)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
response, err := client.Do(req)
|
|
||||||
check(err)
|
|
||||||
defer response.Body.Close()
|
|
||||||
|
|
||||||
body := getHTTPResponseBody(response)
|
|
||||||
check(json.Unmarshal(body, &ticket))
|
check(json.Unmarshal(body, &ticket))
|
||||||
|
|
||||||
return &ticket
|
return &ticket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTicketTimeEntriesByID(site *ConnectwiseSite, ticketID int) *[]TimeEntryReference {
|
||||||
|
|
||||||
|
timeEntryReference := []TimeEntryReference{}
|
||||||
|
|
||||||
|
var Url *url.URL
|
||||||
|
Url, err := url.Parse(site.Site)
|
||||||
|
check(err)
|
||||||
|
Url.Path += fmt.Sprintf("/service/tickets/%d/timeentries", ticketID)
|
||||||
|
|
||||||
|
body := GetRequest(site, Url)
|
||||||
|
check(json.Unmarshal(body, &timeEntryReference)) // *[]TimeEntryReference
|
||||||
|
|
||||||
|
return &timeEntryReference
|
||||||
|
}
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Callback struct {
|
type Callback struct {
|
||||||
Id int
|
ID int
|
||||||
Description string
|
Description string
|
||||||
Url string
|
Url string
|
||||||
ObjectId int
|
ObjectId int
|
||||||
@ -18,7 +18,9 @@ type Callback struct {
|
|||||||
InactiveFlag bool
|
InactiveFlag bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCallbacks(site *ConnectwiseSite) {
|
func GetCallbacks(site *ConnectwiseSite) *[]Callback {
|
||||||
|
|
||||||
|
callbacks := []Callback{}
|
||||||
|
|
||||||
//Build the request URL
|
//Build the request URL
|
||||||
var Url *url.URL
|
var Url *url.URL
|
||||||
@ -27,8 +29,9 @@ func GetCallbacks(site *ConnectwiseSite) {
|
|||||||
Url.Path += "/system/callbacks"
|
Url.Path += "/system/callbacks"
|
||||||
|
|
||||||
body := GetRequest(site, Url)
|
body := GetRequest(site, Url)
|
||||||
fmt.Print(string(body))
|
check(json.Unmarshal(body, &callbacks))
|
||||||
// check(json.Unmarshal(body, &ticket))
|
|
||||||
|
return &callbacks
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,9 +47,8 @@ func NewCallback(site *ConnectwiseSite, callback Callback) {
|
|||||||
|
|
||||||
jsonBuffer := bytes.NewReader(jsonCallback)
|
jsonBuffer := bytes.NewReader(jsonCallback)
|
||||||
|
|
||||||
body := PostRequest(site, Url, jsonBuffer)
|
//body := PostRequest(site, Url, jsonBuffer)
|
||||||
|
PostRequest(site, Url, jsonBuffer)
|
||||||
fmt.Print(string(body))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user