Skip to content

Instantly share code, notes, and snippets.

@vudngo
Created February 14, 2018 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vudngo/603f9d2af27effd7060fae1e474ca07a to your computer and use it in GitHub Desktop.
Save vudngo/603f9d2af27effd7060fae1e474ca07a to your computer and use it in GitHub Desktop.
// DESCRIPTION:
// This script will execute three API calls to Sentry:
// 1. Create a new user and add the user to a team.
// 2. Create a new project.
// 3. Retrieve the project's client key (ie. DSN).
////////////////////////////////////////////////////////////////////////////////////////////////////////
// INSTRUCTIONS:
// 1. Update <ORG_SLUG>, <TEAM_SLUG>, and <PROJECT_SLUG> with real Slug values from your Sentry account.
// 2. Update <EMAIL_ADDRESS> with a real email address
// 3. Update <AUTH_TOKEN> with your Sentry API TOKEN
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
create_user()
create_project()
get_key()
}
func create_user( ) {
fmt.Println("NEW USER:\n")
url := "https://sentry.io/api/0/organizations/<ORG_SLUG>/members/"
payload := strings.NewReader("{\"email\":\"<EMAIL_ADDRESS>\",\"user\":\"<EMAIL_ADDRESS>\",\"teams\":[\"<TEAM_SLUG>\"],\"role\":\"member\"}\n")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer <AUTH_TOKEN>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
func create_project() {
fmt.Println("NEW PROJECT:\n")
url := "https://sentry.io/api/0/teams/<ORG_SLUG>/<TEAM_SLUG>/projects/"
payload := strings.NewReader("{\n \"name\": \"<CAMPAIGN_NAME>\",\n \"slug\": \"<PROJECT_SLUG>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer <AUTH_TOKEN>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
func get_key() {
fmt.Println("GET KEY:\n")
url := "https://sentry.io/api/0/projects/<ORG_SLUG>/<PROJECT_SLUG>/keys/"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <AUTH_TOKEN>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment