Skip to content

Commit

Permalink
Merge pull request #165 from NexWeb/patch-1
Browse files Browse the repository at this point in the history
Update USE_CASES.md
  • Loading branch information
thinkingserious committed Oct 16, 2017
2 parents 3f3b0ec + 968b3e0 commit 87a607a
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion USE_CASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This documentation provides examples for specific use cases. Please [open an iss
* [Substitutions](#substitutions)
* [Sections](#sections)
* [Attachments](#attachments)
* [How to View Email Statistics](#email_stats)
* [How to Setup a Domain Whitelabel](#whitelabel_domain)

<a name="transactional_templates"></a>
# Transactional Templates
Expand Down Expand Up @@ -1340,4 +1342,87 @@ func main() {
fmt.Println(response.Headers)
}
}
```
```

<a name="email_stats"></a>
### How to View Email Statistics
You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics).
To view Email Statistics via the API:
```
package main

import (
"fmt"
"log"
"os"

"github.com/sendgrid/sendgrid-go"
)

func main() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/stats", host)
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["aggregated_by"] = "day"
queryParams["limit"] = "1"
queryParams["start_date"] = "2017-01-01"
queryParams["end_date"] = "2017-10-12"
queryParams["offset"] = "1"
request.QueryParams = queryParams
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
```
<a name="whitelabel_domain"></a>
### How to Setup a Domain Whitelabel
You can find documentation for how to setup a domain whitelabel via the UI [here](https://sendgrid.com/docs/Classroom/Basics/Whitelabel/setup_domain_whitelabel.html).
Find more information about all of SendGrid's whitelabeling related documentation [here](https://sendgrid.com/docs/Classroom/Basics/Whitelabel/index.html).
To create a Domain Whitelabel Via the API:
```
package main

import (
"fmt"
"log"
"os"

"github.com/sendgrid/sendgrid-go"
)

func main() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/whitelabel/domains", host)
request.Method = "POST"
request.Body = []byte(` {
"automatic_security": false,
"custom_spf": true,
"default": true,
"domain": "example.com",
"ips": [
"192.168.1.1",
"192.168.1.2"
],
"subdomain": "SUBDOMAIN",
"username": "YOUR_SENDGRID_SUBUSER_NAME"
}`)
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
```

0 comments on commit 87a607a

Please sign in to comment.