Add Patch
Add AssignTicketToTeam
This commit is contained in:
parent
8909e6f25e
commit
b4d146e6e2
@ -20,6 +20,13 @@ type Request struct {
|
||||
PageSize int
|
||||
}
|
||||
|
||||
//Patch is a struct which holds the required fields to make a PATCH request
|
||||
type Patch struct {
|
||||
Op string `json:"op"`
|
||||
Path string `json:"path"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
//NewRequest is a function which takes the mandatory fields to perform a request to the CW API and returns a pointer to a Request struct
|
||||
func (cw *Site) NewRequest(restAction, method string, body []byte) *Request {
|
||||
req := Request{CW: cw, RestAction: restAction, Method: method, Body: body}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
//Calendar is a struct to hold calendar data extracted from JSON
|
||||
type Calendar struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@ -32,6 +33,7 @@ type Calendar struct {
|
||||
} `json:"_info"`
|
||||
}
|
||||
|
||||
//ScheduleEntry is a struct to hold extracted JSON data
|
||||
type ScheduleEntry struct {
|
||||
ID int `json:"id"`
|
||||
ObjectID int `json:"objectId"`
|
||||
|
@ -3,6 +3,7 @@ package connectwise
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -486,7 +487,7 @@ func (cw *Site) GetBoardTeamByName(boardID int, teamName string) (*BoardTeam, er
|
||||
}
|
||||
|
||||
if len(*boardTeam) == 0 {
|
||||
return nil, fmt.Errorf("connectsise returned no results for %s/%s", boardID, teamName)
|
||||
return nil, fmt.Errorf("connectwise returned no results for %d/%s", boardID, teamName)
|
||||
}
|
||||
|
||||
return &(*boardTeam)[0], nil
|
||||
@ -508,3 +509,32 @@ func (cw *Site) GetBoards() (*[]Board, error) {
|
||||
|
||||
return board, nil
|
||||
}
|
||||
|
||||
//AssignTicketToTeam will set the team/id of a ticket
|
||||
func (cw *Site) AssignTicketToTeam(ticketID, teamID int) (*Ticket, error) {
|
||||
patches := &[]Patch{}
|
||||
patch := &Patch{
|
||||
Op: "replace",
|
||||
Path: "team/id",
|
||||
Value: strconv.Itoa(teamID)}
|
||||
*patches = append(*patches, *patch)
|
||||
|
||||
patchBody, err := json.Marshal(patches)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not marhsal patch json to byte slice: %s", err)
|
||||
}
|
||||
|
||||
req := cw.NewRequest(fmt.Sprintf("/service/tickets/%d", ticketID), "PATCH", patchBody)
|
||||
err = req.Do()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err)
|
||||
}
|
||||
|
||||
ticket := &Ticket{}
|
||||
err = json.Unmarshal(req.Body, ticket)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal body into struct: %s", err)
|
||||
}
|
||||
|
||||
return ticket, nil
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ type Callback struct {
|
||||
} `json:"_info"`
|
||||
}
|
||||
|
||||
//GetMembers returns a slice of Member structs containing all the members (users) of connectwise
|
||||
//GetSystemMembers returns a slice of Member structs containing all the members (users) of connectwise
|
||||
//TBD finish this, I don't have permissions with my API key to see the JSON data
|
||||
func (cw *Site) GetSystemMembers() error {
|
||||
req := cw.NewRequest("/system/members", "GET", nil)
|
||||
err := req.Do()
|
||||
@ -29,8 +30,6 @@ func (cw *Site) GetSystemMembers() error {
|
||||
return fmt.Errorf("request failed for %s: %s", req.RestAction, err)
|
||||
}
|
||||
|
||||
fmt.Println("test")
|
||||
fmt.Println(req.Body)
|
||||
/*
|
||||
callbacks := &[]Callback{}
|
||||
err = json.Unmarshal(req.Body, callbacks)
|
||||
|
Loading…
Reference in New Issue
Block a user