Questions on Deployment API - Send Events
Asked by andrew_pass:

Hi,

We're trying to get events for deployments firing into Compass using the documentation here -

<https://developer.atlassian.com/cloud/compass/components/send-events-using-REST-API/>

And

<https://developer.atlassian.com/cloud/compass/rest/api-group-events/#api-compass-v1-events-post>

We've tried to get our Event ID but we're getting an error back (404) -

{  
"errors": \[  
{  
"type": "CREATE_EVENT_SOURCE_NOT_FOUND",  
"message": "We could not create the event because the event source is not found. Please try again with the correct event source ID."  
}  
\]  
}

Is there something we're missing?

Many thanks,

Andy


Answers:
author: Patrick Brady
body: Hello Andy!  
I'm one of the developers on Compass. Can you send along the mutation that you are using to create the event source and the query you are making to get the event? I want to double check that in the events query you are using the same externalEventSourceId you set in the createEventSource mutation not the eventSourceId of the actual event source that is returned by the mutation.

If that's not the case, having the queries will also help me debug what's going on :)

- Patrick

comments: author: Filip Swiatczak
body: Hi Patrick, I'm the dev doing this with Andy.

Here are the 3 sequential Graphql queries we used as per (<https://developer.atlassian.com/cloud/compass/components/send-events-using-REST-API/>):

```
query example {

  tenantContexts(hostNames:["xxx.atlassian.net"]) {

    cloudId

  }

}

mutation createEventSource {

  compass {

    createEventSource(input: {

        cloudId: "xxx-052c863da88d",

          externalEventSourceId: "automationdeveloperportal",

            eventType: BUILD

     }) {

      eventSource {

        id

      }

      success

      errors {

        message

      }

    }

  }

}
```

```
mutation attachEventSource {

  compass {

    attachEventSource(input: {

eventSourceId: "ari:cloud:compass:f0dc5bce-c8ca-434d-82ec-052c863da88d:event-source/79d4aee6-1e97-4dec-9503-a5ff659cbfe8/f554180edcf52ca26f77307adab7082a63420603b9531bb7e46ea47406387812",

componentId: "ari:cloud:compass:f0dc5bce-c8ca-434d-82ec-052c863da88d:component/79d4aee6-1e97-4dec-9503-a5ff659cbfe8/be39c303-634f-474e-a4f5-1c80b75972da"

}) {

      success

      errors {

        message

      }

    }

  }

}

?
```

This is the Event post Body we are trying with:
>
> ```
> {
>
>   "cloudId": "xxx-052c863da88d",
>
>   "event": {
>
>     "deployment": {
>
>       "updateSequenceNumber": 57,
>
>       "displayName": "test1",
>
>       "url": "https://xxx.uk/job/Automation/job/developer-portal/job/master/",
>
>       "description": "test description",
>
>       "lastUpdated": "2022-03-22T17:37:10Z",
>
>       "externalEventSourceId": "automationdeveloperportal",
>
>       "deploymentProperties": {
>
>         "sequenceNumber": 39,
>
>         "state": "PENDING",
>
>         "pipeline": {
>
>           "pipelineId": "12345",
>
>           "url": "https://xxx.uk/job/Automation/job/developer-portal/job/master/",
>
>           "displayName": "pipeline"
>
>         },
>
>         "environment": {
>
>           "category": "PRODUCTION",
>
>           "displayName": "abcd",
>
>           "environmentId": "live"
>
>         }
>
>       }
>
>     }
>
>   }
>
> }
> ```

Please note we are using externalEventSourceId: "automationdeveloperportal" which was the ID I've given to a jenkins pipeline we've intended as the source of events. It returns:

```
{

    "errors": [

        {

            "type": "CREATE_EVENT_SOURCE_NOT_FOUND",

            "message": "We could not create the event because the event source is not found. Please try again with the correct event source ID."

        }

    ]

}
```

We also tried with eventSourceID, ie the full ari:(...), or random abcd, same results.

The only way I can confirm the event exists is by re-running attachEventSource and getting 'already attached' message. CreateEventSource appears idempotent. An event list query that returns both eventSourceId and externalEventSourceId could be handy.

Thanks!


author: Filip Swiatczak
body: Correction, I got it working.   

To the best of my reading, it is not mentioned explicitly that in REST API :  

```
"event": {

     "type": {
```

has to match the TYPE declared in:  

```
createEventSource(input: {eventType: TYPE
```

might be obvious to some but it took me looking at the EventSource Query in GraphQL, with 3 mandatory parts to locating the EventSource:   

ARGUMENTS  

**cloudId**

ID!

**eventType**

CompassEventType!  
**externalEventSourceId**   

ID!  

<br />

To realise this. Thanks!


author: Luke
body: HI Filip, Thanks for sharing the solution.   

Looks like we need to improve our error message here. I've raised an improvement issue to update this error message, and we'll also add a note in the guide as well.   

- Luke - Compass Engineering Manager


author: Andrew Freedman
body: Hi Andy,

From the [REST API docs](https://developer.atlassian.com/cloud/compass/components/send-events-using-REST-API/#step-1--set-up-an-event-source-using-the-atlassian-platform-graphql-api), did the event source setup work and return you an `EVENT_SOURCE_ID`? (Also, this is for Jenkins deployments, right? The example suggests using an event type of `CUSTOM` but you're better off using `DEPLOYMENT` in this case.)

--- Andrew

comments: author: andrew_pass
body: Hi Andrew,

Thanks for the reply, we managed to get an EventSourceID however when we try to use it we get the error above.

Tried using both the Custom and Deployment types and both get kicked back.

Cheers,

Andy


author: Phill Pafford
body: facing the same issue, how did you resolve this?


author: Dave Fernandes
body: Hey Andy, we have one of our teams looking into it. Will get you an update as soon as we get to the bottom of it.

comments: author: andrew_pass
body: Cheers Dave, much appreciated :)