// 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 ProductsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
/// Number of items to return per page.
///
/// Defaults to `15`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Page number to return.
///
/// Defaults to `1`.
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
/// Include draft products alongside published products.
#[serde(skip_serializing_if = "Option::is_none")]
pub with_drafts: Option<bool>,
/// Return only draft products.
#[serde(skip_serializing_if = "Option::is_none")]
pub only_drafts: Option<bool>,
/// 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 Default for ListParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
limit: Some(15),
page: Some(1),
with_drafts: Default::default(),
only_drafts: Default::default(),
x_store: Default::default(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateParams {
/// 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: SdkCreateProductRequestApplicationJson,
}
impl CreateParams {
/// Construct a new `CreateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkCreateProductRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
/// Include draft products alongside published products.
#[serde(skip_serializing_if = "Option::is_none")]
pub with_drafts: Option<bool>,
/// Return only draft products.
#[serde(skip_serializing_if = "Option::is_none")]
pub only_drafts: Option<bool>,
/// 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 ReplaceParams {
/// 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: SdkReplaceProductRequestApplicationJson,
}
impl ReplaceParams {
/// Construct a new `ReplaceParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkReplaceProductRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateParams {
/// 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: SdkUpdateProductRequestApplicationJson,
}
impl UpdateParams {
/// Construct a new `UpdateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkUpdateProductRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct DeleteParams {
/// 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: SdkDeleteProductRequestApplicationJson,
}
impl DeleteParams {
/// Construct a new `DeleteParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkDeleteProductRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SearchParams {
/// Number of items to return per page.
///
/// Defaults to `15`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Page number to return.
///
/// Defaults to `1`.
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
/// 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: SdkSearchProductsRequestApplicationJson,
}
impl SearchParams {
/// Construct a new `SearchParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkSearchProductsRequestApplicationJson) -> Self {
Self {
limit: Some(15),
page: Some(1),
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BatchCreateParams {
/// 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: SdkBatchCreateProductsRequestApplicationJson,
}
impl BatchCreateParams {
/// Construct a new `BatchCreateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkBatchCreateProductsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BatchUpdateParams {
/// 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: SdkBatchUpdateProductsRequestApplicationJson,
}
impl BatchUpdateParams {
/// Construct a new `BatchUpdateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkBatchUpdateProductsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BatchDeleteParams {
/// 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: SdkBatchDeleteProductsRequestApplicationJson,
}
impl BatchDeleteParams {
/// Construct a new `BatchDeleteParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkBatchDeleteProductsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
impl<'a> ProductsApi<'a> {
/// List all products
///
/// List your store's products, 15 per page by default. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn list(
&self,
params: ListParams,
) -> Result<SdkListProductsResponseValue200ApplicationJson, Error> {
self.list_with_options(params, None).await
}
/// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_with_options(
&self,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkListProductsResponseValue200ApplicationJson, Error> {
self.list_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn list_raw(
&self,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkListProductsResponseValue200ApplicationJson>, Error> {
let path = "/v2/products".to_string();
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("listProducts".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(method, &path, ¶ms, options, "GET /v2/products")
.await
}
/// Create a product
///
/// Create a product in the selected store. Requires a token with the `listing` ability. The same product rules apply as in the dashboard. Add a variant before offering the product at checkout. Include variants to create the product and its initial variants atomically. For a complete bundle, set type to bundle, supply one BUNDLE variant with empty deliverable.data, and include bundle_items. The response includes the created variant IDs in data.variants. Omit these fields to retain separate creation. These options apply to single-product creation, not batch creation. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn create(
&self,
params: CreateParams,
) -> Result<SdkCreateProductResponseValue201ApplicationJson, Error> {
self.create_with_options(params, None).await
}
/// Variant of [`Self::create`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_with_options(
&self,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCreateProductResponseValue201ApplicationJson, Error> {
self.create_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn create_raw(
&self,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkCreateProductResponseValue201ApplicationJson>, Error> {
let path = "/v2/products".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("createProduct".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/products",
)
.await
}
/// Retrieve a product
///
/// Retrieve a product by its ID. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn get(
&self,
product: &str,
params: GetParams,
) -> Result<SdkGetProductResponseValue200ApplicationJson, Error> {
self.get_with_options(product, params, None).await
}
/// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_with_options(
&self,
product: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetProductResponseValue200ApplicationJson, Error> {
self.get_raw(product, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_raw(
&self,
product: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkGetProductResponseValue200ApplicationJson>, Error> {
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getProduct".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/products/{product}",
)
.await
}
/// Update a product
///
/// Update a product in the authenticated store. Requires a token with the `listing` ability. Send `expected_updated_at` to reject stale writes instead of overwriting a newer change. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn replace(
&self,
product: &str,
params: ReplaceParams,
) -> Result<SdkReplaceProductResponseValue200ApplicationJson, Error> {
self.replace_with_options(product, params, None).await
}
/// Variant of [`Self::replace`] that accepts per-request [`crate::RequestOptions`].
pub async fn replace_with_options(
&self,
product: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkReplaceProductResponseValue200ApplicationJson, Error> {
self.replace_raw(product, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn replace_raw(
&self,
product: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkReplaceProductResponseValue200ApplicationJson>, Error> {
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}");
let method = http::Method::PUT;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("replaceProduct".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PUT /v2/products/{product}",
)
.await
}
/// Update a product
///
/// Update a product in the authenticated store. Requires a token with the `listing` ability. Send `expected_updated_at` to reject stale writes instead of overwriting a newer change. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn update(
&self,
product: &str,
params: UpdateParams,
) -> Result<SdkUpdateProductResponseValue200ApplicationJson, Error> {
self.update_with_options(product, params, None).await
}
/// Variant of [`Self::update`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_with_options(
&self,
product: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkUpdateProductResponseValue200ApplicationJson, Error> {
self.update_raw(product, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn update_raw(
&self,
product: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkUpdateProductResponseValue200ApplicationJson>, Error> {
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}");
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("updateProduct".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/products/{product}",
)
.await
}
/// Delete a product
///
/// Soft-delete a product in the authenticated store. Products with active or past-due subscriptions cannot be deleted. Send `expected_updated_at` to reject a stale deletion. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn delete(
&self,
product: &str,
params: DeleteParams,
) -> Result<SdkDeleteProductResponseValue200ApplicationJson, Error> {
self.delete_with_options(product, params, None).await
}
/// Variant of [`Self::delete`] that accepts per-request [`crate::RequestOptions`].
pub async fn delete_with_options(
&self,
product: &str,
params: DeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkDeleteProductResponseValue200ApplicationJson, Error> {
self.delete_raw(product, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn delete_raw(
&self,
product: &str,
params: DeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkDeleteProductResponseValue200ApplicationJson>, Error> {
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}");
let method = http::Method::DELETE;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("deleteProduct".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"DELETE /v2/products/{product}",
)
.await
}
/// Search products
///
/// Search products using JSON body filters, search terms, includes, and sort instructions. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn search(
&self,
params: SearchParams,
) -> Result<SdkSearchProductsResponseValue200ApplicationJson, Error> {
self.search_with_options(params, None).await
}
/// Variant of [`Self::search`] that accepts per-request [`crate::RequestOptions`].
pub async fn search_with_options(
&self,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkSearchProductsResponseValue200ApplicationJson, Error> {
self.search_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn search_raw(
&self,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkSearchProductsResponseValue200ApplicationJson>, Error> {
let path = "/v2/products/search".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("searchProducts".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/products/search",
)
.await
}
/// Batch create products
///
/// Create multiple products in one request by sending a `resources` array. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn batch_create(
&self,
params: BatchCreateParams,
) -> Result<SdkBatchCreateProductsResponseValue200ApplicationJson, Error> {
self.batch_create_with_options(params, None).await
}
/// Variant of [`Self::batch_create`] that accepts per-request [`crate::RequestOptions`].
pub async fn batch_create_with_options(
&self,
params: BatchCreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkBatchCreateProductsResponseValue200ApplicationJson, Error> {
self.batch_create_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn batch_create_raw(
&self,
params: BatchCreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkBatchCreateProductsResponseValue200ApplicationJson>, Error>
{
let path = "/v2/products/batch".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("batchCreateProducts".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/products/batch",
)
.await
}
/// Batch update products
///
/// Update multiple products in one request by sending a `resources` object keyed by product ID. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn batch_update(
&self,
params: BatchUpdateParams,
) -> Result<SdkBatchUpdateProductsResponseValue200ApplicationJson, Error> {
self.batch_update_with_options(params, None).await
}
/// Variant of [`Self::batch_update`] that accepts per-request [`crate::RequestOptions`].
pub async fn batch_update_with_options(
&self,
params: BatchUpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkBatchUpdateProductsResponseValue200ApplicationJson, Error> {
self.batch_update_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn batch_update_raw(
&self,
params: BatchUpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkBatchUpdateProductsResponseValue200ApplicationJson>, Error>
{
let path = "/v2/products/batch".to_string();
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("batchUpdateProducts".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/products/batch",
)
.await
}
/// Batch delete products
///
/// Delete multiple products in one request by sending the product IDs in `resources`. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn batch_delete(
&self,
params: BatchDeleteParams,
) -> Result<SdkBatchDeleteProductsResponseValue200ApplicationJson, Error> {
self.batch_delete_with_options(params, None).await
}
/// Variant of [`Self::batch_delete`] that accepts per-request [`crate::RequestOptions`].
pub async fn batch_delete_with_options(
&self,
params: BatchDeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkBatchDeleteProductsResponseValue200ApplicationJson, Error> {
self.batch_delete_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn batch_delete_raw(
&self,
params: BatchDeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkBatchDeleteProductsResponseValue200ApplicationJson>, Error>
{
let path = "/v2/products/batch".to_string();
let method = http::Method::DELETE;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("batchDeleteProducts".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"DELETE /v2/products/batch",
)
.await
}
}