Created
November 28, 2023 19:36
-
-
Save niski84/b0ae7d536ea9323c587f66fa4020e8f6 to your computer and use it in GitHub Desktop.
jira server using http basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/base64" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
func JiraIssue() { | |
username := "your_username" // Replace with your Jira username | |
password := "your_password" // Replace with your Jira password or token | |
url := "https://jiraServer.net/rest/api/2/issue/CCM-13494" | |
req, err := http.NewRequest("GET", url, nil) | |
if err != nil { | |
fmt.Println("error creating request:", err) | |
return | |
} | |
// Encode credentials | |
credentials := base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) | |
req.Header.Add("Authorization", "Basic "+credentials) | |
req.Header.Add("Content-Type", "application/json") | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
fmt.Println("error sending request:", err) | |
return | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Println("error reading response:", err) | |
return | |
} | |
fmt.Println("Full JSON Response:\n", string(body)) | |
var result map[string]interface{} | |
if err := json.Unmarshal(body, &result); err != nil { | |
fmt.Println("error unmarshaling json:", err) | |
return | |
} | |
if fields, ok := result["fields"].(map[string]interface{}); ok { | |
fmt.Println("Custom Fields:") | |
for key, value := range fields { | |
if bytes.HasPrefix([]byte(key), []byte("customfield_")) { | |
fmt.Printf("%s: %v\n", key, value) | |
} | |
} | |
} | |
customFieldKey := "customfield_XXXX" // Replace with the actual key for "Apv CloudOps" | |
if fields, ok := result["fields"].(map[string]interface{}); ok { | |
if apvCloudOps, ok := fields[customFieldKey]; ok { | |
fmt.Printf("Apv CloudOps: %v\n", apvCloudOps) | |
} else { | |
fmt.Println("Apv CloudOps field not found") | |
} | |
} | |
} | |
func main() { | |
JiraIssue() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment