Skip to main content

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.

Prerequisite

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.

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)