# Shopify Billing Integrity API (`moneybug/shopify-billing-integrity-api`) Actor

Preflight Shopify App Events billing and reconcile usage ledgers to detect billing drift, duplicate retry risks, and aggregate mismatches.

- **URL**: https://apify.com/moneybug/shopify-billing-integrity-api.md
- **Developed by:** [MoneyBug](https://apify.com/moneybug) (community)
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 billing cycle reconciliations

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## MoneyBug Shopify Billing Integrity API

Catch Shopify usage-billing mistakes **before they become merchant disputes or lost revenue**.

Use it when your app sends **Shopify App Events** for usage billing and you need a machine-readable answer to either:

1. **Is this billing event safe to send?**
2. **Does my accepted-event ledger match Shopify's current-cycle usage?**

No Shopify credentials. No repo upload. No database. No paid AI dependency.

### Two billable operations

#### 1) event_preflight — $0.005

Validate one Shopify billing event before send.

Checks include:

- exact meter-handle match
- timestamp and billing-cycle boundaries
- retry / idempotency identity
- post-uninstall timing
- attribute limits and scalar values
- quoted fractional billing values
- zero-value mistakes
- PII and secret-like field risk

Typical result:

```json
{
  "operation": "event_preflight",
  "status": "PASS",
  "findingCount": 0
}
```

#### 2) reconcile_cycle — $0.02

Compare your immutable app-side accepted-event ledger with Shopify current-cycle aggregate usage.

Returns:

- **MATCH**
- **UNDER_REPORTED**
- **OVER_REPORTED**
- **DUPLICATE_RISK**
- **CYCLE_DRIFT**

If the totals differ but public Shopify evidence cannot identify the exact rejected event, MoneyBug returns **UNLOCATABLE_PLATFORM_GAP** instead of guessing.

Typical result:

```json
{
  "operation": "reconcile_cycle",
  "status": "PASS",
  "reconciliationStatus": "MATCH",
  "expectedQuantity": 3,
  "shopifyQuantity": 3,
  "delta": 0
}
```

### Quick start: preflight one event

```json
{
  "mode": "event_preflight",
  "apiVersion": "2026-10",
  "meterHandles": ["api_calls"],
  "event": {
    "shop_id": "gid://shopify/Shop/12345",
    "event_handle": "api_calls",
    "timestamp": "2026-10-09T09:00:00Z",
    "idempotency_key": "usage-0001",
    "attributes": {
      "value": 1
    }
  }
}
```

### Quick start: reconcile one cycle

```json
{
  "mode": "reconcile_cycle",
  "meterHandle": "api_calls",
  "currentBillingCycle": {
    "startTime": "2026-10-01T00:00:00Z",
    "endTime": "2026-11-01T00:00:00Z"
  },
  "sentEvents": [
    {
      "logicalEventId": "usage-001",
      "idempotencyKeyHash": "hash-001",
      "timestamp": "2026-10-05T10:00:00Z",
      "value": 1,
      "transportAccepted": true
    },
    {
      "logicalEventId": "usage-002",
      "idempotencyKeyHash": "hash-002",
      "timestamp": "2026-10-06T10:00:00Z",
      "value": 2,
      "transportAccepted": true
    }
  ],
  "shopifyUsage": {
    "quantity": 3,
    "cost": 0.3,
    "currency": "USD"
  }
}
```

### Good fits

- Shopify apps using usage-based or percentage billing
- CI / release checks before billing changes
- retry and idempotency regression tests
- merchant billing support investigations
- automated finance / billing reconciliation jobs
- AI agents that need a bounded PASS / WARNING / FAIL before emitting a billing event

### Pricing

- **event_preflight:** $0.005 per usable preflight
- **reconcile_cycle:** $0.02 per usable shop + meter + billing-cycle reconciliation
- Platform usage included
- Invalid top-level input is not charged

### Privacy and safety

- No Shopify credentials required
- No repository upload
- No persistence beyond normal Apify run artifacts
- Raw idempotency keys are never echoed; output uses a short SHA-256-derived hash
- Obvious credential-shaped attributes are blocked
- PII detection is conservative and heuristic
- MoneyBug never claims Shopify accepted, rejected, or billed an individual event unless the caller supplies evidence that proves it

### Assurance boundary

MoneyBug does **not**:

- call Shopify on your behalf
- scrape Dev Dashboard
- resend events
- auto-correct billing
- claim Shopify certification
- claim that a PASS proves Shopify billed an event

Current deterministic test record: **55 / 55 PASS**.

This Actor is intentionally separate from MoneyBug App Events Guard and the Shopify Monetization Fingerprint Actor.

# Changelog

This Actor's version history is a separate document: https://apify.com/moneybug/shopify-billing-integrity-api/changelog.md

# Actor input Schema

## `mode` (type: `string`):

Choose whether to validate one billing event before sending or reconcile one billing cycle against Shopify aggregate usage.

## `apiVersion` (type: `string`):

Used for event_preflight metadata only.

## `event` (type: `object`):

For event_preflight. Raw idempotency keys are never echoed in output.

## `meterHandles` (type: `array`):

Exact active Shopify App Pricing meter handles for the scope.

## `currentBillingCycle` (type: `object`):

{ startTime, endTime } from Partner API activeSubscription.

## `uninstalledAt` (type: `string`):

ISO 8601 timestamp used for post-uninstall risk checks.

## `analyticsStandardEvent` (type: `boolean`):

Only enable for an accepted Analytics App Events declaration using a standard shopify.\* handle.

## `meterHandle` (type: `string`):

For reconcile_cycle.

## `sentEvents` (type: `array`):

For reconcile_cycle. Use hashed logical IDs if preferred. Each row: logicalEventId, idempotencyKeyHash, timestamp, value, transportAccepted.

## `shopifyUsage` (type: `object`):

For reconcile_cycle. Supply usage.quantity and optionally cost/currency from Partner API activeSubscription.

## Actor input object example

```json
{
  "mode": "event_preflight",
  "apiVersion": "2026-10",
  "event": {
    "shop_id": "gid://shopify/Shop/12345",
    "event_handle": "api_calls",
    "timestamp": "2026-10-09T09:00:00Z",
    "idempotency_key": "api_calls_12345_0001",
    "attributes": {
      "value": 1
    }
  },
  "analyticsStandardEvent": false
}
```

# Actor output Schema

## `results` (type: `string`):

Structured preflight or reconciliation result.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "event": {
        "shop_id": "gid://shopify/Shop/12345",
        "event_handle": "api_calls",
        "timestamp": "2026-10-09T09:00:00Z",
        "idempotency_key": "api_calls_12345_0001",
        "attributes": {
            "value": 1
        }
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("moneybug/shopify-billing-integrity-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "event": {
        "shop_id": "gid://shopify/Shop/12345",
        "event_handle": "api_calls",
        "timestamp": "2026-10-09T09:00:00Z",
        "idempotency_key": "api_calls_12345_0001",
        "attributes": { "value": 1 },
    } }

# Run the Actor and wait for it to finish
run = client.actor("moneybug/shopify-billing-integrity-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "event": {
    "shop_id": "gid://shopify/Shop/12345",
    "event_handle": "api_calls",
    "timestamp": "2026-10-09T09:00:00Z",
    "idempotency_key": "api_calls_12345_0001",
    "attributes": {
      "value": 1
    }
  }
}' |
apify call moneybug/shopify-billing-integrity-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,moneybug/shopify-billing-integrity-api"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/o4EIKULzcU0ShodFa/builds/DLG5WXcENC36exkDH/openapi.json
