Create and Delete Event Subscriptions

📘

Buy with Prime API is now available for early access

Sign up for early access to the Buy with Prime API using the 'Sign Up' button below. The API may change as Amazon receives feedback and iterates on it.

This topic contains examples of requests and responses that show how to Subscribe to Events.

To learn how to call the Buy with Prime API, see Call the Buy with Prime API.

For troubleshooting, see Troubleshoot Events.


Create an event subscription

The following example uses the createEventSubscription mutation to subscribe to the REFUND_REQUESTED event.

For a list of event types, see Event Types.

Create an event subscription with webhook events

Provide an authProfileId when using OAuth 2.0 or HTTP basic authentication. For details on creating an authentication profile, see Steps to Subscribe to Buy with Prime Events using Webhook Events.

Request
mutation {
    createEventSubscription(
        input: {
            destination: {
                webhook: {
                    httpMethod: "POST",
                    url: "https://my-webhook.com",
                    authProfileId: "my-oauth-profile"
            },
            eventType: "REFUND_REQUESTED"
        }
    ) {
        subscriptionId
    }
}
Response
{
  "data": {
    "createEventSubscription": {
      "subscriptionId": "example-subscription-id"
    }
  }
}

Alternatively, if you didn't previously create an authentication profile, provide OAuth 2.0 or HTTP basic authentication credentials for in-line authentication configuration. However, if you don't create an authentication profile you can't rotate client authorization credentials or use the same authorization credentials for multiple event subscriptions.

Request
mutation {
    createEventSubscription(
        input: {
            destination: {
                webhook: {
                    url: "https://webhook-endpoint.com",
                    method: "POST",
                    authConfig: {
                        oAuthConfig: {
                            clientParameters: {
                                clientId: "client_id_updated",
                                clientSecret: "client_secret_updated"
                            },
                            authEndpoint: "https://auth-endpoint-updated.com",
                            httpMethod: "POST"
                        }
                    }
                }
            }
            eventType: "DELIVERY_COMPLETED"
        }
    ) {
        subscriptionId
    }
}
Response
{
  "data": {
    "createEventSubscription": {
      "subscriptionId": "example-subscription-id"
    }
  }
}

Create an event subscription with Amazon EventBridge

After successful completion of this request, you will see a new partner event source in the Amazon EventBridge console.

Request
// GraphQL mutation

mutation{
  createEventSubscription(
    input:{
      destination:{
        eventBridge:{
         region:"us-east-1"
         partnerEventSource:{ 
            account:"example-aws-account-id"
            name:"example-partner-event-source-name"
          }
        }
      }
      eventType:"REFUND_REQUESTED"
    }
  ){
    subscriptionId
  }
}
Response
{
  "data": {
    "createEventSubscription": {
      "subscriptionId": "example-subscription-id"
    }
  }
}

Delete an event subscription

The following example uses the deleteEventSubscription mutation to delete the subscription with the specified subscriptionId.

Request
// GraphQL mutation

mutation{
  deleteEventSubscription(subscriptionId:"example-subscription-id"){
    subscriptionId
  }
}
Response
{
  "data": {
    "deleteEventSubscription": {
      "subscriptionId": "example-subscription-id"
    }
  }
}

Related topics