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
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"
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 )
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Phill Pafford that makes sense to me, since that's going to still be a unique UUID.
I'm glad this helped solve it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.