Shopify Rust Client
A Rust client library for interacting with the Shopify Admin API. Supports both REST and GraphQL APIs with a focus on app development and order management.
Features
Current Support
Core APIs
- 📦 Orders (REST): Get orders by ID/name, update order properties
- 💳 Subscriptions (GraphQL): Recurring/usage/combined subscriptions, trial management, usage tracking
- 🎁 Discounts (GraphQL): Create and manage automatic app discounts
- ⚙️ App Installation (GraphQL): App metadata, metafields management
- 🛒 Cart Transform (GraphQL): Create cart transformations with metafield support (create & update)
- 🔧 Shopify Functions (GraphQL): List available functions
- 🏪 Shop (GraphQL): Fetch shop owner details, plan info, and billing address
Developer Experience
- 📦 Type-Safe: Strongly typed models for all API responses
- 🚀 Async/Await: Built on
reqwestfor asynchronous HTTP requests - 🔐 Secure: Token-based authentication support
- 🪝 Webhook Support: Parse customer and shop compliance webhooks
- 🔍 Request Callbacks: Optional before/after hooks for observability and logging
- 🎯 Client-Based: Single client instance with organized service modules
Roadmap
- 🚧 Products API: Product management and variants
- 🚧 Customers API: Customer management and search
- 🚧 Inventory API: Inventory tracking and locations
- 🚧 Fulfillments API: Order fulfillment operations
- 🚧 Additional Webhooks: Support for more webhook topics beyond compliance
- 🚧 Rate Limiting: Built-in request throttling and retry logic
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Or install directly:
Public API
The library exposes the following public modules:
ShopifyClient- Main client for making API callstypes- All type definitions organized by resource (e.g.,types::order,types::subscription)webhooks- Webhook parsing utilities and types- Callback Types -
BeforeRequestCallback,AfterRequestCallback,RequestCallbacks
use ShopifyClient; // Main client
use *; // Order types
use *; // Subscription types
use *; // Shop types
use *; // Webhook utilities
use ; // Callback types
Usage
Initialize the Client
use ShopifyClient;
let client = new;
Initialize with Request Callbacks
use ShopifyClient;
use Arc;
let before_request = new;
let after_request = new;
let client = new_with_callbacks;
Get Order by ID
use ShopifyClient;
async
Get Order by Name
use ShopifyClient;
async
Update Order (Patch)
use ShopifyClient;
use ;
async
Create Recurring Subscription
use ShopifyClient;
use ;
async
Create Automatic App Discount
use ShopifyClient;
use DiscountAutomaticAppInput;
async
Create Cart Transform with Metafields
use ShopifyClient;
use ;
async
Update Metafields on Existing Cart Transform
use ShopifyClient;
use MetafieldsSetInput;
async
Update Metafields with Compare-and-Set (CAS)
For safe concurrent updates, use the compare_digest field to ensure the metafield hasn't changed since you last read it:
use ShopifyClient;
use MetafieldsSetInput;
async
Get Shop Owner Details
use ShopifyClient;
async
Parse Webhooks
use ;
Project Structure
The library is organized into a modular structure for easy extensibility:
src/
├── lib.rs # Main client entry point and exports
├── types/ # Public type definitions
│ ├── mod.rs # Type module exports
│ ├── order.rs # Order types (REST)
│ ├── subscription.rs # Subscription types (GraphQL)
│ ├── discount.rs # Discount types (GraphQL)
│ ├── app_installation.rs # App installation types (GraphQL)
│ ├── cart_transform.rs # Cart transform types (GraphQL)
│ ├── shop.rs # Shop types (GraphQL)
│ └── shopify_functions.rs # Shopify functions types (GraphQL)
├── webhooks/ # Public webhook parsing module
│ ├── mod.rs # Webhook parsing functions
│ └── types.rs # Webhook payload types
├── common/ # Internal shared utilities (private)
│ ├── mod.rs
│ ├── types.rs # Common types (APIError, RequestCallbacks)
│ ├── utils.rs # Utility functions
│ └── http.rs # Centralized GraphQL execution
└── services/ # Internal API services (private)
├── order/ # Order service (REST)
├── subscription/ # Subscription service (GraphQL)
├── discount/ # Discount service (GraphQL)
├── app_installation/ # App installation service (GraphQL)
├── cart_transform/ # Cart transform service (GraphQL)
├── shop/ # Shop service (GraphQL)
└── shopify_functions/ # Shopify functions service (GraphQL)
├── mod.rs # Service struct with public methods
└── remote.rs # Internal API implementation
Design Philosophy
- Client-Based: Initialize a
ShopifyClientonce and access services through it - Clean Public API: Three public modules -
ShopifyClient,types, andwebhooks - Encapsulation: All internal implementation (
common,services) is private - Service-Oriented: Each API resource (orders, products, etc.) is its own service module
- Clear Separation: Services for outgoing API calls, webhooks for incoming data parsing
- Type Safety: All API responses are strongly typed with comprehensive models
Data Models
The library provides strongly-typed models organized by resource:
Order Types (types::order)
- Order: Complete order information including customer, line items, fulfillments, pricing, and timestamps
- Customer: Customer details (ID, email, phone, name, addresses)
- LineItem: Product line items with quantities, prices, properties, and fulfillment status
- OrderFulfillment: Fulfillment tracking with tracking numbers, URLs, and shipment status
- Address: Billing and shipping address information
- PriceSet: Multi-currency pricing with shop and presentment money
- Property: Custom line item properties
- PatchOrderRequest / PatchOrder: Request types for updating orders
Subscription Types (types::subscription)
- CreateRecurringSubscriptionRequest: Create recurring app subscriptions
- CreateUsageSubscriptionRequest: Create usage-based subscriptions
- CreateCombinedSubscriptionRequest: Create subscriptions with both recurring and usage pricing
- CreateUsageRecordRequest: Record usage for usage-based subscriptions
- AppPricingInterval: Subscription billing intervals (Every30Days, Annual)
- CreateSubscriptionResp: Subscription creation response with confirmation URL
- ActiveSubscriptionsResp: List of active app subscriptions
Discount Types (types::discount)
- DiscountAutomaticAppInput: Create automatic app discounts
- DiscountAutomaticAppUpdateInput: Update existing automatic app discounts
- DiscountAutomaticAppCreateResp: Discount creation response
- DiscountNodesResp: List discounts with pagination support
App Installation Types (types::app_installation)
- GetCurrentAppInstallationResp: Current app installation details
- MetafieldInput: Input for creating/updating metafields
- SetMetafieldsResp: Metafield operation response
- GetMetafieldResp / ListMetafieldsResp: Metafield retrieval responses
Cart Transform Types (types::cart_transform)
- CartTransformCreateInput: Create cart transformation functions
- CartTransformCreateResp: Cart transform creation response
- MetafieldInput: Metafield input for cart transform creation
- MetafieldsSetInput: Update or create metafields on existing resources
- MetafieldsSetResp: Metafields set response with updated metafield data
- Metafield: Metafield data with timestamps and compare digest for CAS
Shop Types (types::shop)
- GetShopResp: Response wrapper for the shop query
- Shop: Shop information including owner details, plan, and addresses
- StaffMember: Account owner details (ID, name, email)
- Domain: Primary domain information
- ShopPlan: Billing plan details (display name, partner development, Shopify Plus)
- ShopAddress: Shop billing address
Shopify Functions Types (types::shopify_functions)
- ShopifyFunctionsResp: List of available Shopify Functions
Webhook Types (webhooks::types)
- CustomersDataRequestPayload: Customer data request webhook payload
- CustomersRedactPayload: Customer redaction webhook payload
- ShopRedactPayload: Shop redaction webhook payload
- WebhookPayload: Enum containing all webhook payload types
- WebhookParseError: Error type for webhook parsing failures
- WebhookCustomer: Customer information in webhook payloads
Error Handling
The library uses a custom APIError enum for comprehensive error handling:
Errors are returned through Result<T, APIError> for easy error propagation and handling.
Authentication
This client requires a Shopify Admin API access token. You can obtain one by:
- Creating a custom app in your Shopify admin panel
- Generating an Admin API access token
- Granting the necessary permissions (e.g.,
read_orders,write_orders)
Request Callbacks
The library supports optional before/after request callbacks for logging, monitoring, and observability:
use ShopifyClient;
use Arc;
let before = new;
let after = new;
let client = new_with_callbacks;
Features:
- Callbacks are synchronous closures that fire before and after every request
- Access token is NOT passed to callbacks for security
- Callbacks use panic catching to prevent user errors from crashing requests
- Works for both REST and GraphQL requests
- Optional - use
new()for no callbacks,new_with_callbacks()for callbacks
API Version
Currently uses Shopify Admin API version 2026-01.
Requirements
- Rust 1.56 or later (2021 edition)
- Dependencies:
reqwest(with JSON support)serde(with derive feature)serde_json
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under your preferred license.
Disclaimer
This is an unofficial Shopify client library. For official SDKs and documentation, visit Shopify's Developer Documentation.