Repository navigation
Expand file tree
/
Copy pathReplenishmentSample.cs
More file actions
100 lines (94 loc) · 4.67 KB
/
Copy pathReplenishmentSample.cs
File metadata and controls
100 lines (94 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment;
using FikaAmazonAPI.Utils;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace FikaAmazonAPI.SampleCode
{
public class ReplenishmentSample
{
AmazonConnection amazonConnection;
public ReplenishmentSample(AmazonConnection amazonConnection)
{
this.amazonConnection = amazonConnection;
}
/// <summary>
/// Find Subscribe-and-Save offers that have paused or at-risk deliveries in the next 30 days,
/// sorted by inventory ascending so the most worrying ones surface first.
/// </summary>
public async Task<ListOffersResponse> ListAtRiskOffersAsync()
{
return await amazonConnection.Replenishment.ListOffersAsync(new ListOffersRequest
{
Pagination = new ListOffersRequestPagination { Limit = 100, Offset = 0 },
Filters = new ListOffersRequestFilters
{
MarketplaceId = amazonConnection.GetCurrentMarketplace.ID,
ProgramTypes = new List<ProgramType> { ProgramType.SUBSCRIBE_AND_SAVE },
DeliveriesConditions = new List<DeliveryConditionType>
{
//DeliveryConditionType.NEXT_30_DAYS_DELIVERIES_PAUSED_PRICING,
//DeliveryConditionType.NEXT_30_DAYS_DELIVERIES_PAUSED_NON_BUYABLE,
DeliveryConditionType.NEXT_30_DAYS_DELIVERIES_AT_LOW_INVENTORY_RISK,
//DeliveryConditionType.NEXT_30_DAYS_DELIVERIES_AT_LOW_INVENTORY_RISK_ONLY,
},
},
Sort = new ListOffersRequestSort
{
Order = SortOrder.ASC,
Key = ListOffersSortKey.INVENTORY,
},
});
}
/// <summary>
/// Pull per-offer metrics for the previous calendar month at the offer level (with SKU
/// and FulfillmentChannelType, both added in the April 2026 release).
/// </summary>
public async Task<ListOfferMetricsResponse> GetOfferMetricsForLastMonthAsync()
{
var lastMonthStart = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0, DateTimeKind.Utc).AddMonths(-1);
var lastMonthEnd = lastMonthStart.AddMonths(1).AddSeconds(-1);
return await amazonConnection.Replenishment.ListOfferMetricsAsync(new ListOfferMetricsRequest
{
Pagination = new ListOfferMetricsRequestPagination { Limit = 500, Offset = 0 },
Filters = new ListOfferMetricsRequestFilters
{
AggregationFrequency = AggregationFrequency.MONTH,
TimeInterval = new TimeInterval { StartDate = lastMonthStart, EndDate = lastMonthEnd },
TimePeriodType = TimePeriodType.PERFORMANCE,
MarketplaceId = amazonConnection.GetCurrentMarketplace.ID,
ProgramTypes = new List<ProgramType> { ProgramType.SUBSCRIBE_AND_SAVE },
},
Sort = new ListOfferMetricsRequestSort
{
Order = SortOrder.DESC,
Key = ListOfferMetricsSortKey.TOTAL_SUBSCRIPTIONS_REVENUE,
},
});
}
/// <summary>
/// Pull seller-level metrics for the previous calendar month including the new
/// REVENUE_PENETRATION metric (April 2026 release).
/// </summary>
public async Task<GetSellingPartnerMetricsResponse> GetSellingPartnerMetricsAsync()
{
var lastMonthStart = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0, DateTimeKind.Utc).AddMonths(-1);
var lastMonthEnd = lastMonthStart.AddMonths(1).AddSeconds(-1);
return await amazonConnection.Replenishment.GetSellingPartnerMetricsAsync(new GetSellingPartnerMetricsRequest
{
AggregationFrequency = AggregationFrequency.MONTH,
TimeInterval = new TimeInterval { StartDate = lastMonthStart, EndDate = lastMonthEnd },
TimePeriodType = TimePeriodType.PERFORMANCE,
MarketplaceId = amazonConnection.GetCurrentMarketplace.ID,
ProgramTypes = new List<ProgramType> { ProgramType.SUBSCRIBE_AND_SAVE },
Metrics = new List<Metric>
{
Metric.TOTAL_SUBSCRIPTIONS_REVENUE,
Metric.SHIPPED_SUBSCRIPTION_UNITS,
Metric.ACTIVE_SUBSCRIPTIONS,
Metric.REVENUE_PENETRATION,
},
});
}
}
}