Comprehensive API documentation for managing subscriptions, payments, and related operations. These APIs allow you to programmatically manage subscription lifecycles, handle payments, configure products, and integrate subscription functionality into your applications.
- Get subscription fulfillment details for latest order
External APIs (0.0.1)
Request
Retrieves the complete, unprocessed subscription contract data directly from Shopify's GraphQL API. This endpoint returns the full Shopify subscription contract object exactly as Shopify provides it, including all nested fields, relationships, and GraphQL metadata.
What This Endpoint Returns: Unlike processed/transformed endpoints, this returns Shopify's raw SubscriptionContract GraphQL object with all available fields. This is the same data structure you would receive if querying Shopify's GraphQL API directly, making it ideal for:
- Debugging Shopify data synchronization issues
- Accessing fields not exposed in other endpoints
- Understanding complete Shopify contract structure
- Building custom integrations requiring full data
- Comparing Shopify source data with processed data
Data Included:
Contract Core:
- Full subscription contract object from Shopify
- All GraphQL __typename fields preserved
- Complete nested object structures
- All available Shopify contract fields
Customer Information:
- Complete customer object with all fields
- Default address details
- Customer tags and metadata
- Marketing preferences
Line Items:
- Full line item details with edges/nodes structure
- Product and variant complete objects
- Pricing policies with all cycle discounts
- Line item custom attributes
- Current and original prices
Billing & Delivery:
- Complete billing policy object
- Full delivery policy details
- Delivery method with all fields
- Delivery price breakdown
- Billing anchor details
Payment Information:
- Payment method details (if available)
- Customer payment instrument
- Payment gateway information
Orders & History:
- Origin order details
- Last payment status
- Historical billing attempts (in Appstle)
Use Cases:
1. Debugging & Troubleshooting:
- Investigate data sync discrepancies
- Verify what Shopify actually stores
- Debug webhook payload issues
- Compare expected vs actual data
2. Advanced Integrations:
- Access Shopify-specific fields not in standard APIs
- Build custom analytics using raw data
- Integrate with Shopify GraphQL directly
- Extract fields for custom processing
3. Data Analysis:
- Analyze complete contract structure
- Extract all available metadata
- Build comprehensive data exports
- Perform deep data audits
4. Development & Testing:
- Understand Shopify's data model
- Test new feature development
- Verify API responses
- Documentation and examples
Response Structure:
Returns SubscriptionContractQuery.SubscriptionContract object:
{
"id": "gid://shopify/SubscriptionContract/123456789",
"status": "ACTIVE",
"nextBillingDate": "2024-03-15T00:00:00Z",
"customer": {
"id": "gid://shopify/Customer/987654321",
"email": "customer@example.com",
"displayName": "John Doe",
"__typename": "Customer"
},
"lines": {
"edges": [
{
"node": {
"id": "gid://shopify/SubscriptionLine/111111",
"quantity": 2,
"variantId": "gid://shopify/ProductVariant/222222",
"title": "Monthly Coffee Box",
"variantTitle": "Medium Roast",
"currentPrice": {
"amount": "29.99",
"currencyCode": "USD"
},
"pricingPolicy": {...},
"__typename": "SubscriptionLine"
}
}
]
},
"billingPolicy": {
"interval": "MONTH",
"intervalCount": 1,
"minCycles": 3,
"maxCycles": 12
},
"deliveryPolicy": {...},
"deliveryMethod": {...},
"__typename": "SubscriptionContract"
}Important Considerations:
Data Source:
- Queries Shopify GraphQL API in real-time
- NOT cached in Appstle database
- Always returns current Shopify state
- Subject to Shopify API rate limits
Performance:
- Slower than database queries (500-1500ms typical)
- Makes real-time call to Shopify
- Response size can be large (10-50 KB)
- Use sparingly to avoid rate limits
GraphQL Structure:
- Includes __typename fields throughout
- Uses GraphQL ID format (gid://shopify/...)
- Nested edges/nodes structure for lists
- All fields as defined in Shopify's schema
Best Practices:
- Use for Debugging: Perfect for troubleshooting data issues
- Avoid Polling: Don't call repeatedly - use cached/processed endpoints instead
- Cache Response: Cache the response if using for display
- Parse Carefully: Handle GraphQL structure (edges/nodes)
- Monitor Rate Limits: Each call counts against Shopify API limits
When to Use vs Other Endpoints:
Use this endpoint when:
- Need complete Shopify contract data
- Debugging synchronization issues
- Accessing Shopify-specific fields
- Building Shopify GraphQL integrations
Use /api/external/v2/subscription-contract-details when:
- Need processed, filtered contract data
- Want faster response times
- Querying multiple contracts
- Building customer-facing UIs
Authentication: Requires valid X-API-Key header
- https://subscription-admin.appstle.com/api/external/v2/subscription-contracts/contract-external/{contractId}
- curl
- JavaScript
- Node.js
- Python
- Java
- C#
- PHP
- Go
- Ruby
- R
- Payload
curl -i -X GET \
'https://subscription-admin.appstle.com/api/external/v2/subscription-contracts/contract-external/{contractId}?api_key=string' \
-H 'X-API-Key: string'{ "get__typename": "string", "id": "string", "createdAt": {}, "updatedAt": {}, "nextBillingDate": {}, "status": "ACTIVE", "deliveryPrice": { "get__typename": "string", "amount": {}, "currencyCode": "USD" }, "lastPaymentStatus": "SUCCEEDED", "billingPolicy": { "get__typename": "string", "interval": "DAY", "intervalCount": 0, "anchors": [ … ], "maxCycles": 0, "minCycles": 0 }, "deliveryPolicy": { "get__typename": "string", "interval": "DAY", "intervalCount": 0, "anchors": [ … ] }, "lines": { "get__typename": "string", "nodes": [ … ], "pageInfo": { … } }, "customerPaymentMethod": { "get__typename": "string", "id": "string", "instrument": { … }, "revokedAt": {}, "revokedReason": "AUTHORIZE_NET_GATEWAY_NOT_ENABLED" }, "deliveryMethod": { "get__typename": "string" }, "originOrder": { "get__typename": "string", "id": "string", "name": "string", "fulfillmentOrders": { … } }, "customer": { "get__typename": "string", "id": "string", "email": "string", "displayName": "string", "firstName": "string", "lastName": "string", "phone": "string" }, "discounts": { "get__typename": "string", "nodes": [ … ], "pageInfo": { … } }, "note": "string", "customAttributes": [ { … } ], "billingAttempts": { "get__typename": "string", "nodes": [ … ] } }
Request
Retrieves fulfillment information for the most recent successful order associated with a subscription contract. This includes tracking details, shipment status, delivery estimates, and fulfillment line items from Shopify.
What This Endpoint Returns: Complete fulfillment data for the subscription's last successfully billed order, queried in real-time from Shopify's GraphQL API. Shows customers when and how their subscription items will be (or were) delivered.
Fulfillment Data Included:
Shipment Tracking:
- Tracking numbers and URLs
- Carrier information (USPS, FedEx, UPS, etc.)
- Tracking company details
- Tracking status updates
Delivery Status:
- Fulfillment status (fulfilled, in_transit, out_for_delivery, delivered, etc.)
- Estimated delivery date
- Actual delivery timestamp (if delivered)
- Delivery method (shipping, pickup, local delivery)
Fulfillment Details:
- Fulfilled line items (which products shipped)
- Quantities fulfilled
- Fulfillment service (manual, automated, 3PL)
- Fulfillment created/updated dates
- Multiple fulfillments (if order shipped in parts)
Location Information:
- Fulfillment location/warehouse
- Origin address details
- Fulfillment service name
Order Determination Logic:
Which Order is Retrieved:
- Finds most recent SUCCESS billing attempt for contract
- If found: Uses that order's Shopify order ID
- If none: Falls back to subscription's origin order ID
- Queries Shopify for that order's fulfillments
Why This Matters:
- Shows CURRENT/LATEST fulfillment status
- Not historical fulfillments from months ago
- Reflects what customer is waiting for NOW
- Updates after each new billing cycle
Use Cases:
1. Customer Portal "Where's My Order":
- Display tracking information
- Show estimated delivery date
- Provide carrier tracking links
- Update fulfillment status
2. Subscription Order Tracking:
- Track recurring order deliveries
- Monitor fulfillment progress
- Identify delayed shipments
- Provide proactive delivery updates
3. Customer Support:
- Answer "where is my order" questions
- Verify shipment details
- Troubleshoot delivery issues
- Provide accurate tracking info
4. Automated Notifications:
- Send tracking emails automatically
- Notify customers of shipments
- Alert on delivery completion
- Trigger review request flows
5. Subscription Management:
- Show fulfillment in subscription history
- Display delivery patterns
- Track fulfillment reliability
- Monitor shipping performance
Response Structure:
Returns Shopify Order object with fulfillments:
{
"id": "gid://shopify/Order/123456789",
"name": "#1001",
"fulfillmentOrders": {
"edges": [
{
"node": {
"id": "gid://shopify/FulfillmentOrder/111111",
"status": "SUCCESS",
"fulfillments": {
"edges": [
{
"node": {
"trackingInfo": [
{
"number": "1Z999AA10123456784",
"url": "https://wwwapps.ups.com/tracking/...",
"company": "UPS"
}
],
"status": "IN_TRANSIT",
"estimatedDeliveryAt": "2024-03-20T00:00:00Z",
"deliveredAt": null
}
}
]
}
}
}
]
}
}Common Scenarios:
Scenario: Order Fulfilled & Shipped
{
"trackingInfo": [{"number": "9400...", "company": "USPS"}],
"status": "IN_TRANSIT",
"estimatedDeliveryAt": "2024-03-18T00:00:00Z"
}Scenario: Order Delivered
{
"status": "DELIVERED",
"deliveredAt": "2024-03-15T14:23:00Z"
}Scenario: Not Yet Fulfilled
{
"fulfillmentOrders": {
"edges": [
{
"node": {
"status": "OPEN",
"fulfillments": {"edges": []}
}
}
]
}
}Scenario: No Order Yet (New Subscription) Returns null or empty response
Important Considerations:
Real-Time Shopify Query:
- Makes live call to Shopify GraphQL API
- NOT cached data
- Response time: 500-1500ms
- Subject to Shopify rate limits
Data Freshness:
- Returns current fulfillment status from Shopify
- Tracking updates reflect Shopify's data
- May lag behind carrier's actual status
- Shopify updates tracking periodically
Null Responses:
- Returns null if no orders exist yet
- Returns null if order ID not found
- Handle gracefully in UI
Multiple Fulfillments:
- Order may have multiple fulfillments (split shipments)
- Each fulfillment has own tracking
- Iterate through all fulfillment nodes
Integration Example:
Customer Portal - Track Shipment:
const order = await fetch(
`/api/external/v2/subscription-contract-details/subscription-fulfillments/${contractId}`,
{ headers: { 'X-API-Key': 'your-key' } }
).then(r => r.json());
if (!order) {
return '<p>No shipment information available yet.</p>';
}
const fulfillments = order.fulfillmentOrders?.edges || [];
fulfillments.forEach(fo => {
fo.node.fulfillments?.edges?.forEach(f => {
const tracking = f.node.trackingInfo?.[0];
if (tracking) {
console.log(`Track with ${tracking.company}: ${tracking.number}`);
console.log(`URL: ${tracking.url}`);
}
});
});Best Practices:
- Cache Response: Cache for 30-60 minutes to reduce Shopify API calls
- Handle Nulls: Always check for null/empty responses
- Parse GraphQL: Navigate edges/nodes structure carefully
- Show All Tracking: Display all fulfillments if multiple shipments
- Link to Carrier: Provide clickable tracking URLs
Authentication: Requires valid X-API-Key header
- https://subscription-admin.appstle.com/api/external/v2/subscription-contract-details/subscription-fulfillments/{contractId}
- curl
- JavaScript
- Node.js
- Python
- Java
- C#
- PHP
- Go
- Ruby
- R
- Payload
curl -i -X GET \
'https://subscription-admin.appstle.com/api/external/v2/subscription-contract-details/subscription-fulfillments/{contractId}?api_key=string' \
-H 'X-API-Key: string'{ "get__typename": "string", "id": "string", "fulfillmentOrders": { "get__typename": "string", "nodes": [ … ], "pageInfo": { … } } }
Request
Retrieves the current billing cycle number for a specific subscription contract. The cycle number represents how many successful billing attempts have occurred for this subscription, starting from 1 for the initial order.
What is a Billing Cycle? A billing cycle represents one completed billing period in a subscription's lifetime. Each successful billing attempt increments the cycle count. This number is crucial for:
- Tracking subscription progress towards minimum/maximum cycle limits
- Applying cycle-based pricing adjustments (discounts after N cycles)
- Determining eligibility for cancellation (minimum cycles requirement)
- Calculating customer lifetime value
- Analyzing subscription retention metrics
How Cycle Counting Works:
Initial Order:
- Cycle 1 starts when subscription is first created
- Initial order counts as the first billing cycle
- Includes origin order that created the subscription
Subsequent Orders:
- Each successful billing attempt increments cycle by 1
- Only SUCCESS status billing attempts are counted
- Failed/skipped billing attempts do NOT increment cycle
- Paused subscriptions maintain their current cycle number
Calculation Formula:
Current Cycle = 1 + (Number of Successful Billing Attempts)Example Timeline:
- Day 1: Subscription created, initial order → Cycle 1
- Day 30: First recurring order successful → Cycle 2
- Day 60: Second recurring order successful → Cycle 3
- Day 90: Billing fails (payment declined) → Still Cycle 3
- Day 95: Retry successful → Cycle 4
Use Cases:
1. Cancellation Eligibility:
- Verify customer has met minimum cycle requirement
- Enforce contract terms (e.g., "3 month minimum")
- Display "Can cancel after N more orders" messaging
- Block premature cancellations
2. Pricing Adjustments:
- Apply introductory pricing for first N cycles
- Trigger loyalty discounts after X cycles
- Calculate when pricing changes take effect
- Implement "First 3 months 50% off" promotions
3. Customer Retention:
- Identify subscriptions at risky cycle counts
- Send retention campaigns at specific milestones
- Track average cycles before churn
- Celebrate subscription anniversaries
4. Analytics & Reporting:
- Calculate customer lifetime value (cycle × price)
- Analyze subscription duration distribution
- Track retention curves by cohort
- Measure success of lifecycle campaigns
5. Customer Portal Display:
- Show "Order #X of Y" progress indicators
- Display remaining cycles until cancellation allowed
- Show subscription tenure/loyalty status
- Calculate and display subscription value earned
Response Format:
Returns a single integer representing the current cycle number:
3Response Examples:
New subscription (just created):
1After 5 successful billing attempts:
6Note: Initial order (1) + 5 successful renewals = Cycle 6
Important Considerations:
Cycle vs. Billing Attempts:
- Failed billing attempts don't increment cycle
- Skipped orders don't increment cycle
- Manual order creation may not increment cycle
- Cycle represents successful billing events only
Paused Subscriptions:
- Cycle number remains frozen while paused
- Resumes at same cycle when un-paused
- Pause duration doesn't affect cycle count
Minimum/Maximum Cycles:
minCycles: Minimum cycles before cancellation allowedmaxCycles: Subscription auto-expires after this many cycles- Use this endpoint to check progress towards these limits
Data Source:
- Queries Appstle database (not Shopify API)
- Counts records in subscription_billing_attempt table
- Filters by SUCCESS status only
- Fast response time (< 100ms typically)
Integration Example:
Check if customer can cancel:
// Get subscription details
const contract = await getSubscriptionContract(contractId);
const currentCycle = await fetch(
`/api/external/v2/subscription-contract-details/current-cycle/${contractId}`,
{ headers: { 'X-API-Key': 'your-key' } }
).then(r => r.json());
const minCycles = contract.minCycles || 0;
if (currentCycle >= minCycles) {
console.log('Customer can cancel now');
showCancelButton();
} else {
const cyclesRemaining = minCycles - currentCycle;
console.log(`Must complete ${cyclesRemaining} more orders before canceling`);
showMinimumCommitmentMessage(cyclesRemaining);
}Display progress to max cycles:
const currentCycle = await getCycleNumber(contractId);
const maxCycles = contract.maxCycles;
if (maxCycles) {
const progress = (currentCycle / maxCycles) * 100;
console.log(`Subscription ${progress.toFixed(0)}% complete (${currentCycle}/${maxCycles})`);
if (currentCycle === maxCycles) {
console.log('This is the final cycle - subscription will expire after this order');
}
}Performance Characteristics:
Fast Query:
- Simple database count query
- Indexed by shop and contractId
- Typical response time: 50-150ms
- Suitable for real-time UI updates
Best Practices:
- Cache Results: Cache cycle number briefly (few minutes) to reduce API calls
- Combine with Contract Data: Fetch contract details simultaneously for min/max cycles
- Handle Edge Cases: Account for subscriptions with no successful billings yet
- Display Progress: Show cycle number in customer-friendly format ("Order 3 of 12")
- Sync with Billing: Update cycle number after each billing attempt completes
Common Misunderstandings:
Myth: Cycle = Months Subscribed
- Reality: Cycle = Successful billing attempts, not time elapsed
- A paused subscription stays at same cycle for months
- Failed payments don't advance the cycle
Myth: First order is Cycle 0
- Reality: Cycles start at 1, not 0
- Initial/origin order is Cycle 1
Related Fields:
minCycles: Minimum cycles before cancellation (from contract)maxCycles: Maximum cycles before auto-expiry (from contract)billingInterval: Frequency between cycles (from contract)
Authentication: Requires valid X-API-Key header
- https://subscription-admin.appstle.com/api/external/v2/subscription-contract-details/current-cycle/{contractId}
- curl
- JavaScript
- Node.js
- Python
- Java
- C#
- PHP
- Go
- Ruby
- R
- Payload
curl -i -X GET \
'https://subscription-admin.appstle.com/api/external/v2/subscription-contract-details/current-cycle/{contractId}' \
-H 'X-API-Key: sk_live_1234567890abcdef'1