@@ -73,6 +73,104 @@ public void CreateSubscription()
7373 } ) ;
7474 }
7575
76+ /// <summary>
77+ /// End-to-end SQS notification setup following the documented workflow:
78+ /// https://developer-docs.amazon.com/sp-api/docs/set-up-notifications-with-amazon-sqs
79+ ///
80+ /// Step 1: Grant SP-API permission to write to your SQS queue (done in AWS Console).
81+ /// Step 2: (Optional) Grant SP-API access to your SSE key via AWS KMS.
82+ /// Step 3: Create a destination using your SQS ARN.
83+ /// Step 4: Create a subscription for the desired notification type.
84+ /// </summary>
85+ public void SetUpSqsNotifications ( )
86+ {
87+ // Step 3: Create a destination (grantless operation — no seller authorization needed)
88+ var destination = amazonConnection . Notification . CreateDestination (
89+ new AmazonSpApiSDK . Models . Notifications . CreateDestinationRequest ( )
90+ {
91+ Name = "CompanyName_SQS" ,
92+ ResourceSpecification = new AmazonSpApiSDK . Models . Notifications . DestinationResourceSpecification
93+ {
94+ Sqs = new AmazonSpApiSDK . Models . Notifications . SqsResource ( "arn:aws:sqs:us-east-2:9999999999999:NAME" )
95+ }
96+ } ) ;
97+
98+ if ( destination == null )
99+ {
100+ Console . WriteLine ( "Failed to create destination." ) ;
101+ return ;
102+ }
103+
104+ Console . WriteLine ( $ "Destination created: { destination . DestinationId } ") ;
105+
106+ // Step 4: Create a subscription using the destinationId from Step 3.
107+ //
108+ // processingDirective is optional and only supported for two notification types:
109+ //
110+ // (A) ANY_OFFER_CHANGED — supports:
111+ // - MarketplaceIds: limit notifications to specific marketplaces
112+ // (useful when you sell in many marketplaces but only track pricing in a few)
113+ // - AggregationTimePeriod: FiveMinutes or TenMinutes
114+ // (useful for high-volume catalogs to reduce notification flood)
115+ //
116+ // (B) ORDER_CHANGE — supports:
117+ // - OrderChangeTypes: "BuyerRequestedChange", "OrderStatusChange"
118+ // (useful when you only need cancellation requests, not every status update)
119+ // - AggregationTimePeriod: FiveMinutes or TenMinutes
120+ // - NOTE: MarketplaceIds is NOT supported for ORDER_CHANGE
121+ //
122+ // Using processingDirective with any other notification type returns HTTP 400.
123+
124+ // Example A: ANY_OFFER_CHANGED with marketplace filter + aggregation
125+ var subscription = amazonConnection . Notification . CreateSubscription (
126+ new ParameterCreateSubscription ( )
127+ {
128+ destinationId = destination . DestinationId ,
129+ notificationType = NotificationType . ANY_OFFER_CHANGED ,
130+ payloadVersion = "1.0" ,
131+ processingDirective = new AmazonSpApiSDK . Models . Notifications . ProcessingDirective
132+ {
133+ EventFilter = new AmazonSpApiSDK . Models . Notifications . EventFilter
134+ {
135+ EventFilterType = "ANY_OFFER_CHANGED" ,
136+ MarketplaceIds = new List < string > { "ATVPDKIKX0DER" } ,
137+ AggregationSettings = new AmazonSpApiSDK . Models . Notifications . AggregationSettings
138+ {
139+ AggregationTimePeriod = AmazonSpApiSDK . Models . Notifications . AggregationTimePeriod . FiveMinutes
140+ }
141+ }
142+ }
143+ } ) ;
144+
145+ if ( subscription == null )
146+ {
147+ Console . WriteLine ( "Failed to create subscription." ) ;
148+ return ;
149+ }
150+
151+ Console . WriteLine ( $ "Subscription created: { subscription . SubscriptionId } ") ;
152+
153+ // Example B: ORDER_CHANGE filtered to buyer cancellation requests only
154+ var orderChangeSub = amazonConnection . Notification . CreateSubscription (
155+ new ParameterCreateSubscription ( )
156+ {
157+ destinationId = destination . DestinationId ,
158+ notificationType = NotificationType . ORDER_CHANGE ,
159+ payloadVersion = "1.0" ,
160+ processingDirective = new AmazonSpApiSDK . Models . Notifications . ProcessingDirective
161+ {
162+ EventFilter = new AmazonSpApiSDK . Models . Notifications . EventFilter
163+ {
164+ EventFilterType = "ORDER_CHANGE" ,
165+ OrderChangeTypes = new List < string > { "BuyerRequestedChange" }
166+ }
167+ }
168+ } ) ;
169+
170+ if ( orderChangeSub != null )
171+ Console . WriteLine ( $ "ORDER_CHANGE subscription created: { orderChangeSub . SubscriptionId } ") ;
172+ }
173+
76174
77175 public async Task StartReceivingNotificationMessagesAsync ( CancellationToken cancellationToken )
78176 {
0 commit comments