-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathputRequest.go
More file actions
85 lines (71 loc) · 2.01 KB
/
Copy pathputRequest.go
File metadata and controls
85 lines (71 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
const (
siteName string = "{{yourSiteName}}"
apiUrl string = "https://" + siteName + ".teamwork.com/"
apiKey string = "{{yourApiKey}}"
dataPreference string = "json"
)
var (
companyId string = "{{yourCompanyId}}"
projectId string = "{{yourProjectId}}"
endPoint string = "projects/" + projectId + "." + dataPreference
)
type ProjectJson struct {
Project `json:"project"`
}
type Project struct {
Category_id string `json:"category-id"`
CompanyID string `json:"companyId"`
Description string `json:"description"`
EndDate string `json:"endDate"`
Harvest_timers_enabled bool `json:"harvest-timers-enabled"`
Name string `json:"name"`
NewCompany string `json:"newCompany"`
PrivacyEnabled bool `json:"privacyEnabled"`
ReplyByEmailEnabled bool `json:"replyByEmailEnabled"`
StartDate string `json:"startDate"`
}
func main() {
putRequest(endPoint)
}
func putRequest(endPoint string) {
data := ProjectJson{
Project{
Category_id: "0",
CompanyID: companyId,
Description: "Edited project",
EndDate: "",
Harvest_timers_enabled: true,
Name: "Edited New Project",
NewCompany: "",
PrivacyEnabled: true,
ReplyByEmailEnabled: true,
StartDate: "",
}}
jsonPayload, err := json.Marshal(data)
if err != nil {
log.Fatal(err)
}
client := &http.Client{}
req, err := http.NewRequest("PUT", apiUrl+endPoint, bytes.NewBuffer(jsonPayload))
req.Header.Add("Authorization", "Basic "+basicAuth(apiKey))
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
s := string(body)
log.Printf(s)
}
func basicAuth(apiKey string) string {
return base64.StdEncoding.EncodeToString([]byte(apiKey))
}