Skip to content

Instantly share code, notes, and snippets.

@phillpafford
Created September 19, 2023 13:05
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 phillpafford/3b0cdd5a0eae78bdefb5fda04a906486 to your computer and use it in GitHub Desktop.
Save phillpafford/3b0cdd5a0eae78bdefb5fda04a906486 to your computer and use it in GitHub Desktop.
atlassian compass custom event
#!/usr/bin/env bash
## requires jq to be installed
set -e
# https://developer.atlassian.com/cloud/compass/rest/intro/#version
TIMESTAMP=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
COMPASS_CLOUD_INSTANCE=name-of-your-instance
COMPASS_REST_API_VERSION=v1
## create api token for your user https://id.atlassian.com/manage-profile/security
COMPASS_USER_EMAIL=your-atlassian-email@example.com
COMPASS_USER_TOKEN=your-super-secret-token
COMPASS_BASE_URL="https://$COMPASS_CLOUD_INSTANCE.atlassian.net/gateway/api/compass/$COMPASS_REST_API_VERSION/events"
## NOTE: need to create the metric in the UI first and get the GUID/UUID
COMPASS_CLOUD_ID="myuuid-1234-4321-abcd-1a2b3cd45e"
COMPASS_CUSTOM_DISPLAY_NAME="my-custom-metric-name"
COMPASS_CUSTOM_UPDATE_SEQUENCE_NUMBER=42
COMPASS_CUSTOM_DESCRIPTION="my-custom-metric-description"
COMPASS_CUSTOM_URL="https://www.google.com"
## this is the name you created
COMPASS_CUSTOM_EXTERNAL_EVENT_SOURCE_ID="my-custom-metric-external-source"
COMPASS_CUSTOM_CUSTOM_EVENT_PROPERTIES_ID="1"
COMPASS_CUSTOM_CUSTOM_EVENT_PROPERTIES_ICON=INFO
# "custom": {
# "displayName": "<string>",
# "lastUpdated": "<string>",
# "updateSequenceNumber": 57,
# "description": "<string>",
# "url": "<string>",
# "externalEventSourceId": "<string>",
# "customEventProperties": {
# "id": "<string>",
# "icon": "INFO"
# }
# },
## data needs to be JSON, use JQ for this
COMPASS_EVENT_JSON_DATA=$( jq -n \
--arg cloudId "$COMPASS_CLOUD_ID" \
--arg cDisplayName "$COMPASS_CUSTOM_DISPLAY_NAME" \
--arg cLastUpdated "$TIMESTAMP" \
--argjson cUpdateSequenceNumber $COMPASS_CUSTOM_UPDATE_SEQUENCE_NUMBER \
--arg cDescription "$COMPASS_CUSTOM_DESCRIPTION" \
--arg cUrl "$COMPASS_CUSTOM_URL" \
--arg cExternalEventSourceId "$COMPASS_CUSTOM_EXTERNAL_EVENT_SOURCE_ID" \
--arg cCustomEventPropertiesId "$COMPASS_CUSTOM_CUSTOM_EVENT_PROPERTIES_ID" \
--arg cCustomEventPropertiesIcon "$COMPASS_CUSTOM_CUSTOM_EVENT_PROPERTIES_ICON" \
'{cloudId: $cloudId, event: {custom: {displayName: $cDisplayName, lastUpdated: $cLastUpdated, updateSequenceNumber: $cUpdateSequenceNumber, description: $cDescription, url: $cUrl, externalEventSourceId: $cExternalEventSourceId, customEventProperties: {id: $cCustomEventPropertiesId, icon: $cCustomEventPropertiesIcon}}}}'
)
## uncomment to debug
# echo ""
# echo $COMPASS_EVENT_JSON_DATA
# echo ""
COMPASS_EVENT=`curl --request POST \
--url $COMPASS_BASE_URL \
--user $COMPASS_USER_EMAIL:$COMPASS_USER_TOKEN \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data "$COMPASS_EVENT_JSON_DATA"`
echo "COMPASS_EVENT: $COMPASS_EVENT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment