package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://graphigo-business.prd.galaxy.eco/query"
accessToken := "access-token-of-yours"
// Request payload
payload := map[string]interface{}{
"operationName": "credentialItems",
"query": `
mutation credentialItems($credId: ID!, $operation: Operation!, $items: [String!]!) {
credentialItems(input: { credId: $credId, operation: $operation, items: $items }) {
name
}
}
`,
"variables": map[string]interface{}{
"credId": "123", // Ensure it's a string
"operation": "APPEND",
"items": []string{"0x123"},
},
}
// Convert payload to JSON
payloadBytes, err := json.Marshal(payload)
if err != nil {
fmt.Println("Error marshalling payload:", err)
return
}
// Create HTTP request
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payloadBytes))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// Add headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("access-token", accessToken)
// Send HTTP request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
// Read response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
// Parse response
var result map[string]interface{}
err = json.Unmarshal(body, &result)
if err != nil {
fmt.Println("Error unmarshalling response:", err)
return
}
// Check for errors
if errors, ok := result["errors"]; ok {
fmt.Println("GraphQL Errors:", errors)
} else {
fmt.Println("Success:", result["data"])
}
}