// This file is auto-generated by oagen. Do not edit.
use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;
pub struct ExportsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListExportsParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateExportParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkCreateExportRequestApplicationJson,
}
impl CreateExportParams {
/// Construct a new `CreateExportParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkCreateExportRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetExportParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct DownloadExportParams {
/// Expiry timestamp from the generated download URL.
///
/// Required.
pub expires: i64,
/// Copy the signature from the response-supplied download_url. The example is illustrative and cannot authorize a download.
///
/// Required.
pub signature: String,
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
impl DownloadExportParams {
/// Construct a new `DownloadExportParams` with the required fields set.
#[allow(deprecated)]
pub fn new(expires: i64, signature: impl Into<String>) -> Self {
Self {
expires,
signature: signature.into(),
x_store: Default::default(),
}
}
}
impl<'a> ExportsApi<'a> {
/// List exports
///
/// List permitted exports, 50 per page. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request. Sales, tax and customer reports require invoice store permission. Affiliate payout reports require affiliate and affiliate:payout permissions. The category selects the applicable permission checks; listing returns only authorized categories.
pub async fn list_exports(
&self,
params: ListExportsParams,
) -> Result<SdkListExportsResponseValue200ApplicationJson, Error> {
self.list_exports_with_options(params, None).await
}
/// Variant of [`Self::list_exports`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_exports_with_options(
&self,
params: ListExportsParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkListExportsResponseValue200ApplicationJson, Error> {
self.list_exports_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn list_exports_raw(
&self,
params: ListExportsParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkListExportsResponseValue200ApplicationJson>, Error> {
let path = "/v2/exports".to_string();
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("listExports".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(method, &path, ¶ms, options, "GET /v2/exports")
.await
}
/// Create an export
///
/// Create a queued sales, tax, customer or affiliate payout report. One export may be queued or running per store, and two per requesting account across all credentials and stores. When capacity is full, HTTP 429 includes Retry-After: 60; poll the existing export and wait before creating another. Date ranges include both end dates and may span at most 366 calendar days. Omitted or null to defaults to today; omitted or null from defaults to 365 days before to. Sales and tax use sale update dates; customers and affiliate payouts use creation dates. Reports are limited to 10,000 source rows, 5 MiB of serialized source data and a 10 MiB output file. Tax summaries count source sales toward these limits. A report that exceeds a limit fails without publishing a partial file; request a smaller date range. Jobs may wait up to 15 minutes to start and run for at most 60 seconds. The requesting actor is recorded but is not returned in this response. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request. Sales, tax and customer reports require invoice store permission. Affiliate payout reports require affiliate and affiliate:payout permissions. The category selects the applicable permission checks; listing returns only authorized categories.
pub async fn create_export(
&self,
params: CreateExportParams,
) -> Result<SdkCreateExportResponseValue201ApplicationJson, Error> {
self.create_export_with_options(params, None).await
}
/// Variant of [`Self::create_export`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_export_with_options(
&self,
params: CreateExportParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCreateExportResponseValue201ApplicationJson, Error> {
self.create_export_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn create_export_raw(
&self,
params: CreateExportParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkCreateExportResponseValue201ApplicationJson>, Error> {
let path = "/v2/exports".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("createExport".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/exports",
)
.await
}
/// Retrieve an export
///
/// Poll until completed, failed, or expired. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request. Sales, tax and customer reports require invoice store permission. Affiliate payout reports require affiliate and affiliate:payout permissions. The category selects the applicable permission checks; listing returns only authorized categories.
pub async fn get_export(
&self,
export: &str,
params: GetExportParams,
) -> Result<SdkGetExportResponseValue200ApplicationJson, Error> {
self.get_export_with_options(export, params, None).await
}
/// Variant of [`Self::get_export`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_export_with_options(
&self,
export: &str,
params: GetExportParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetExportResponseValue200ApplicationJson, Error> {
self.get_export_raw(export, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_export_raw(
&self,
export: &str,
params: GetExportParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkGetExportResponseValue200ApplicationJson>, Error> {
let export = crate::client::path_segment(export);
let path = format!("/v2/exports/{export}");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getExport".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/exports/{export}",
)
.await
}
/// Download an export
///
/// Validate the five-minute signed API URL, then redirect to a short-lived private object-storage URL. The API does not stream the file. Pending or running exports return 409; expired exports return 410. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request. Sales, tax and customer reports require invoice store permission. Affiliate payout reports require affiliate and affiliate:payout permissions. The category selects the applicable permission checks; listing returns only authorized categories.
pub async fn download_export(
&self,
export: &str,
params: DownloadExportParams,
) -> Result<(), Error> {
self.download_export_with_options(export, params, None)
.await
}
/// Variant of [`Self::download_export`] that accepts per-request [`crate::RequestOptions`].
pub async fn download_export_with_options(
&self,
export: &str,
params: DownloadExportParams,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
self.download_export_raw(export, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn download_export_raw(
&self,
export: &str,
params: DownloadExportParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<()>, Error> {
let export = crate::client::path_segment(export);
let path = format!("/v2/exports/{export}/download");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("downloadExport".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/exports/{export}/download",
)
.await
}
}