getAffiliateAnalytics method
Get Affiliate Analytics Returns the project affiliates with their totals for a period, oldest joiner first. Affiliates with no activity in the period are omitted. Note 1: this endpoint is only accessible with a secret API key. Note 2: a period may span at most 90 days; request a longer window a period at a time. Note 3: up to 100 affiliates are returned per request; page through the rest with `offset`.
Parameters:
from- The first day of the period, inclusive, as YYYY-MM-DD (UTC).to- The last day of the period, inclusive, as YYYY-MM-DD (UTC). Must not be beforefrom, and the period must be at most 90 days long.xApiKey- The secret API key.limit- How many affiliates to return, from 10 to 100.offset- How many affiliates to skip before the page.cancelToken- ACancelTokenthat can be used to cancel the operationheaders- Can be used to add additional headers to the requestextras- Can be used to add flags to the requestvalidateStatus- AValidateStatuscallback that can be used to determine request success based on the HTTP status of the responseonSendProgress- AProgressCallbackthat can be used to get the send progressonReceiveProgress- AProgressCallbackthat can be used to get the receive progress
Returns a Future containing a Response with a AffiliateAnalyticsResponse as data
Throws DioException if API call or serialization fails
Implementation
Future<Response<AffiliateAnalyticsResponse>> getAffiliateAnalytics({
required Date from,
required Date to,
required String xApiKey,
num? limit = 100,
num? offset = 0,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/analytics/affiliates';
final _options = Options(
method: r'GET',
headers: <String, dynamic>{
r'x-api-key': xApiKey,
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
validateStatus: validateStatus,
);
final _queryParameters = <String, dynamic>{
if (limit != null) r'limit': encodeQueryParameter(_serializers, limit, const FullType(num)),
if (offset != null) r'offset': encodeQueryParameter(_serializers, offset, const FullType(num)),
r'from': encodeQueryParameter(_serializers, from, const FullType(Date)),
r'to': encodeQueryParameter(_serializers, to, const FullType(Date)),
};
final _response = await _dio.request<Object>(
_path,
options: _options,
queryParameters: _queryParameters,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
AffiliateAnalyticsResponse? _responseData;
try {
final rawResponse = _response.data;
_responseData = rawResponse == null ? null : _serializers.deserialize(
rawResponse,
specifiedType: const FullType(AffiliateAnalyticsResponse),
) as AffiliateAnalyticsResponse;
} catch (error, stackTrace) {
throw DioException(
requestOptions: _response.requestOptions,
response: _response,
type: DioExceptionType.unknown,
error: error,
stackTrace: stackTrace,
);
}
return Response<AffiliateAnalyticsResponse>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}