-
Notifications
You must be signed in to change notification settings - Fork 260
/
eventwebhook.go
57 lines (52 loc) · 1.42 KB
/
eventwebhook.go
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
package main
import (
"fmt"
"log"
"os"
"github.com/sendgrid/rest"
"github.com/sendgrid/sendgrid-go"
"github.com/sendgrid/sendgrid-go/helpers/eventwebhook"
)
// EnableSignedWebhook : Enables Signed Event Webhook.
// PATCH /user/webhooks/event/settings/signed
func EnableSignedWebhook() {
var err error
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/user/webhooks/event/settings/signed", host)
request.Method = rest.Patch
s := eventwebhook.NewSettings()
s.SetEnableSignedWebhook(true)
request.Body, err = eventwebhook.GetRequestBody(s)
if err != nil {
log.Println(err)
return
}
response, err := sendgrid.MakeRequest(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
// GetPublicKeyForSignedWebhook : Get Public Key for Event Webhook.
// Get /user/webhooks/event/settings/signed
func GetPublicKeyForSignedWebhook() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/user/webhooks/event/settings/signed", host)
request.Method = rest.Get
response, err := sendgrid.MakeRequest(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
func main() {
// add your function calls here
}