Compass: Delete externalEventSourceId for specific eventType using the RestAPI

Phill Pafford
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2025

 

How can I Delete externalEventSourceId for specific eventType using the RestAPI

or GraphQL using a curl command?

 

I ran into a limit and all my rest api scripts are failing now, as there is no way to delete this data

 

https://community.atlassian.com/t5/Compass-questions/ATTACHED-EVENT-SOURCE-LIMIT-REACHED/qaq-p/2942043

 

example script:

 

#!/usr/bin/env bash

set -e


COMPASS_CLOUD_INSTANCE=acme

COMPASS_REST_API_VERSION=v1

## create api token for your user https://id.atlassian.com/manage-profile/security

## @todo pull from ENV Variable

COMPASS_USER_EMAIL=me@email.com
COMPASS_USER_TOKEN=super.long.token.here


CLOUD_ID="3123123123-2222-47d0-8ad2-7sdfe5td"


## https://hello.atlassian.net/gateway/api/graphql

COMPASS_BASE_URL="https://$COMPASS_CLOUD_INSTANCE.atlassian.net/gateway/api/graphql"

echo "COMPASS_BASE_URL: $COMPASS_BASE_URL"


# The GraphQL query you want to execute

QUERY="mutation DeleteEventSourceMutation {

compass {

deleteEventSource(

input: {

cloudId: \"$CLOUD_ID\",

externalEventSourceId: \"text-of-external-event-source-id\",

eventType: \"DEPLOYMENT\"

}

) {

success

}

}

}"

echo "QUERY: $QUERY"


# Construct the GraphQL request

REQUEST_BODY=$(jq -n --arg query "$QUERY" '{query: $query}')

echo "REQUEST_BODY: $REQUEST_BODY"


## X-ExperimentalApi: DevOpsBeta


## X-ExperimentalApi: compass-beta

# COMPASS_GRAPHQL=$(curl -g \

# --request POST \

# --url $COMPASS_BASE_URL \

# --user $COMPASS_USER_EMAIL:$COMPASS_USER_TOKEN \

# --header 'Accept: application/json' \

# --header 'Content-Type: application/json' \

# --header 'X-ExperimentalApi: DevOpsBeta' \

# --data "$REQUEST_BODY")




COMPASS_GRAPHQL=$(curl -s -X POST \

-H "Authorization: Bearer $COMPASS_USER_TOKEN" \

-H "Content-Type: application/json" \

-d "$REQUEST_BODY" \

"$COMPASS_BASE_URL")


echo "COMPASS_GRAPHQL: $COMPASS_GRAPHQL"

1 answer

1 accepted

4 votes
Answer accepted
Enrique Serrano Valle
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 12, 2025

For manually-added event sources, you can delete them using the GraphQL API.

Example:
 

curl -X POST \
-u "yourUsernameEmail:your-long-api-key" \
-H "Content-Type: application/json" \
-H "X-ExperimentalApi: DevOpsBeta" \
-H "X-ExperimentalApi: compass-beta" \
-d '{
"query": "mutation DeleteEventSourceMutation { compass { deleteEventSource( input: { cloudId: \"your-cloud-id\", externalEventSourceId: \"test_id\", eventType: ALERT } ) { success errors { message extensions { statusCode errorType}} } } }"
}' \
https://your-site.atlassian.net/gateway/api/graphql

Note that `eventType` is an enum and not a string, so no need for quotes around that or otherwise it'd throw a validation error.

You need to be a Compass admin to have permission to do this as well.

(To test your queries, it can also be faster to use the GraphQL explorer, in your-site.atlassian.net/gateway/api/graphql )

Phill Pafford
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2025

OMG YES!, this is so much easier 

your-site.atlassian.net/gateway/api/graphql

Follow up question:

since Bamboo does not have access to Bitbucket repo UUID, would using the first commit hash be acceptable and an externalEventSourceId?

git rev-list --parents HEAD | tail -1

 

Like # people like this
Enrique Serrano Valle
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2025

@Phill Pafford that makes sense to me, since that's going to still be a unique UUID.

I'm glad this helped solve it!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events