Testing Notification Payloads
This example demonstrates how to send a test notification to Causely using a representative payload. It follows the same pattern as the examples above: reuse your token + GraphQL client helpers and then execute one mutation with a clear variables object.
This example reuses the helper utilities defined in the Authentication and GraphQL Clients sections—fetching an access token, creating the GraphQL client, and sending a request with the post_query wrapper (CLI, Python, or Go). Keep those helpers in scope before running this mutation.
- python
- javascript
- bash
- go
- graphql
import os
import json
if __name__ == "__main__":
# Get credentials from environment
cid, secret = os.getenv("CAUSELY_CLIENT_ID"), os.getenv("CAUSELY_CLIENT_SECRET")
if not cid or not secret:
raise EnvironmentError("Missing CAUSELY_CLIENT_ID or CAUSELY_CLIENT_SECRET")
# Get access token and create GraphQL client
token = get_causely_access_token(cid, secret)
client = create_graphql_client(token)
# Prepare mutation
mutation = """
mutation createNotification($notification: NotificationInput!) {
createNotification(notification: $notification)
}
"""
# Build the payload
embedded_payload = {
"link": "https://portal.causely.app",
"name": "Causely: Test Notification 42",
"type": "ProblemDetected", # Options are ProblemDetected and ProblemCleared
"entity": {
"id": "22307647-43e6-5f08-a5e4-a3f50088ccec",
"link": "https://portal.causely.app",
"name": "payments-api",
"type": "Node"
},
"labels": {
"k8s.cluster.name": "us-prod", # Test to route based on cluster
"k8s.namespace.name": "payments", # Test to route based on name space
"gcp.resource.zone": "https://www.gcp.com/compute/v1/projects/example-project/zones/us-central1-a",
"causely.ai/cluster": "my-important-services-cluster"
},
"objectId": "2ac21477-61f3-4ae0-9fc4-0c1ea43ff727",
"severity": "High", # Options are Critical, High, Medium, Low
"timestamp": "2025-09-14T19:15:16.410543344Z",
"description": {
"summary": "Sending test notification for entity in us-prod myApp1",
"details": "Webhook Test"
}
}
variables = {
"notification": {
"sourceId": "2f423693-5334-4586-a366-64d458535001",
"type": 1,
"payload": json.dumps(embedded_payload)
}
}
result = post_query(client, mutation, variables)
print(result)
// Reuses helpers defined above: getCauselyAccessToken, createGraphQLClient
// Requires @apollo/client installed (as shown above)
const { CAUSELY_CLIENT_ID, CAUSELY_CLIENT_SECRET } = process.env;
const { gql } = require('@apollo/client');
if (!CAUSELY_CLIENT_ID || !CAUSELY_CLIENT_SECRET) {
console.error('Missing CAUSELY_CLIENT_ID or CAUSELY_CLIENT_SECRET');
process.exit(1);
}
(async () => {
try {
const token = await getCauselyAccessToken(CAUSELY_CLIENT_ID, CAUSELY_CLIENT_SECRET);
const client = createGraphQLClient(token);
// Mutation matches working script exactly
const mutation = `
mutation createNotification($notification: NotificationInput!) {
createNotification(notification: $notification)
}
`;
// Embedded payload (stringified below)
const embeddedPayload = {
link: 'https://portal.causely.app',
name: 'Causely: Test Notification 42',
type: 'ProblemDetected', // ProblemDetected | ProblemCleared
entity: {
id: '22307647-43e6-5f08-a5e4-a3f50088ccec',
link: 'https://portal.causely.app',
name: 'payments-api',
type: 'Node',
},
labels: {
'k8s.cluster.name': 'us-prod',
'k8s.namespace.name': 'payments',
'gcp.resource.zone': 'https://www.gcp.com/compute/v1/projects/example-project/zones/us-central1-a',
'causely.ai/cluster': 'my-important-services-cluster',
},
objectId: '2ac21477-61f3-4ae0-9fc4-0c1ea43ff727',
severity: 'High', // Critical | High | Medium | Low
timestamp: '2025-09-14T19:15:16.410543344Z',
description: {
summary: 'Sending test notification for entity in us-prod myApp1',
details: 'Webhook Test',
},
};
const variables = {
notification: {
sourceId: '2f423693-5334-4586-a366-64d458535001',
type: 1,
payload: JSON.stringify(embeddedPayload),
},
};
// Use mutate for a GraphQL mutation
const result = await client.mutate({ mutation: gql(mutation), variables });
console.log(JSON.stringify(result.data, null, 2));
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}
})();
# Assumes CAUSELY_ACCESS_TOKEN is already exported (see Authentication section)
# Creates files for the mutation, an embedded payload JSON, and variables (with payload as a JSON string), then posts them.
# 1) GraphQL mutation
cat > create_notification.graphql << 'EOF'
mutation createNotification($notification: NotificationInput!) {
createNotification(notification: $notification)
}
EOF
# 2) Embedded payload (domain JSON)
cat > embedded_payload.json << 'EOF'
{
"link": "https://portal.causely.app",
"name": "Causely: Test Notification 42",
"type": "ProblemDetected",
"entity": {
"id": "22307647-43e6-5f08-a5e4-a3f50088ccec",
"link": "https://portal.causely.app",
"name": "payments-api",
"type": "Node"
},
"labels": {
"k8s.cluster.name": "us-prod",
"k8s.namespace.name": "payments",
"gcp.resource.zone": "https://www.gcp.com/compute/v1/projects/example-project/zones/us-central1-a",
"causely.ai/cluster": "my-important-services-cluster"
},
"objectId": "2ac21477-61f3-4ae0-9fc4-0c1ea43ff727",
"severity": "High",
"timestamp": "2025-09-14T19:15:16.410543344Z",
"description": {
"summary": "Sending test notification for entity in us-prod myApp1",
"details": "Webhook Test"
}
}
EOF
# 3) Build variables.json with payload as a *string* using jq to JSON-encode the file content
PAYLOAD_STR=$(jq -Rs . < embedded_payload.json)
cat > variables.json << EOF
{
"notification": {
"sourceId": "2f423693-5334-4586-a366-64d458535001",
"type": 1,
"payload": ${PAYLOAD_STR}
}
}
EOF
# 4) Post using gq if available; otherwise curl
if command -v gq &> /dev/null; then
gq https://api.causely.app/query/ \
--header "Authorization: Bearer ${CAUSELY_ACCESS_TOKEN}" \
--query-file create_notification.graphql \
--variables-file variables.json
else
curl -sS -X POST https://api.causely.app/query/ \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${CAUSELY_ACCESS_TOKEN}" \
-d "{\"query\":\"$(tr '\n' ' ' < create_notification.graphql)\",\"variables\":$(cat variables.json)}"
fi
# 5) Clean up
rm -f create_notification.graphql embedded_payload.json variables.json
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
// Reuse helpers defined above:
// getToken(id, secret, url) and createGraphQLClient(accessToken)
id, secret := os.Getenv("CAUSELY_CLIENT_ID"), os.Getenv("CAUSELY_CLIENT_SECRET")
if id == "" || secret == "" {
fmt.Fprintln(os.Stderr, "Missing CAUSELY_CLIENT_ID or CAUSELY_CLIENT_SECRET")
os.Exit(1)
}
token, err := getToken(id, secret, "https://auth.causely.app/frontegg/identity/resources/auth/v2/api-token")
if err != nil {
fmt.Fprintln(os.Stderr, "Error getting token:", err)
os.Exit(1)
}
client := createGraphQLClient(token)
// Mutation matches working script exactly
mutation := `
mutation createNotification($notification: NotificationInput!) {
createNotification(notification: $notification)
}
`
// Embedded payload (will be stringified)
embeddedPayload := map[string]interface{}{
"link": "https://portal.causely.app",
"name": "Causely: Test Notification 42",
"type": "ProblemDetected",
"entity": map[string]interface{}{
"id": "22307647-43e6-5f08-a5e4-a3f50088ccec",
"link": "https://portal.causely.app",
"name": "payments-api",
"type": "Node",
},
"labels": map[string]interface{}{
"k8s.cluster.name": "us-prod",
"k8s.namespace.name": "payments",
"gcp.resource.zone": "https://www.gcp.com/compute/v1/projects/example-project/zones/us-central1-a",
"causely.ai/cluster": "my-important-services-cluster",
},
"objectId": "2ac21477-61f3-4ae0-9fc4-0c1ea43ff727",
"severity": "High",
"timestamp": "2025-09-14T19:15:16.410543344Z",
"description": map[string]interface{}{
"summary": "Sending test notification for entity in us-prod myApp1",
"details": "Webhook Test",
},
}
payloadBytes, err := json.Marshal(embeddedPayload)
if err != nil {
fmt.Fprintln(os.Stderr, "Error marshaling payload:", err)
os.Exit(1)
}
variables := map[string]interface{}{
"notification": map[string]interface{}{
"sourceId": "2f423693-5334-4586-a366-64d458535001",
"type": 1,
"payload": string(payloadBytes), // GraphQL expects a STRING here
},
}
result, err := postQuery(client, mutation, variables)
if err != nil {
fmt.Fprintln(os.Stderr, "Error running mutation:", err)
os.Exit(1)
}
fmt.Println(result)
}
When sending a notification via GraphQL, the payload field must be passed as a stringified JSON (not as a nested JSON object). The embedded JSON represents the notification details and must be stringified before being sent in the GraphQL variables.
Below is a clear breakdown:
Mutation:
mutation createNotification($notification: NotificationInput!) {
createNotification(notification: $notification)
}
Embedded Payload (JSON)
This is the JSON you want to send as the notification payload (before stringifying):
{
"link": "https://portal.causely.app",
"name": "Causely: Test Notification 42",
"type": "ProblemDetected",
"entity": {
"id": "22307647-43e6-5f08-a5e4-a3f50088ccec",
"link": "https://portal.causely.app",
"name": "payments-api",
"type": "Node"
},
"labels": {
"k8s.cluster.name": "us-prod",
"k8s.namespace.name": "payments",
"gcp.resource.zone": "https://www.gcp.com/compute/v1/projects/example-project/zones/us-central1-a",
"causely.ai/cluster": "my-important-services-cluster"
},
"objectId": "2ac21477-61f3-4ae0-9fc4-0c1ea43ff727",
"severity": "High",
"timestamp": "2025-09-14T19:15:16.410543344Z",
"description": {
"summary": "Sending test notification for entity in us-prod myApp1",
"details": "Webhook Test"
}
}
Variables (GraphQL input)
Notice that the
payload value is the above JSON, stringified (escaped), and can be split across multiple lines for readability:{
"notification": {
"sourceId": "2f423693-5334-4586-a366-64d458535001",
"type": 1,
"payload": "{\n \"link\": \"https://portal.causely.app\",\n \"name\": \"Causely: Test Notification 42\",\n \"type\": \"ProblemDetected\",\n \"entity\": {\n \"id\": \"22307647-43e6-5f08-a5e4-a3f50088ccec\",\n \"link\": \"https://portal.causely.app\",\n \"name\": \"payments-api\",\n \"type\": \"Node\"\n },\n \"labels\": {\n \"k8s.cluster.name\": \"us-prod\",\n \"k8s.namespace.name\": \"payments\",\n \"gcp.resource.zone\": \"https://www.gcp.com/compute/v1/projects/example-project/zones/us-central1-a\",\n \"causely.ai/cluster\": \"my-important-services-cluster\"\n },\n \"objectId\": \"2ac21477-61f3-4ae0-9fc4-0c1ea43ff727\",\n \"severity\": \"High\",\n \"timestamp\": \"2025-09-14T19:15:16.410543344Z\",\n \"description\": {\n \"summary\": \"Sending test notification for entity in us-prod myApp1\",\n \"details\": \"Webhook Test\"\n }\n}"
}
}
Note:
Thepayloadfield must be a string. Most clients will use a function likeJSON.stringify()to convert the embedded payload JSON into a string before passing it to the GraphQL mutation.This lets you clearly see how the original JSON maps into the string value required by the GraphQL API.