Cart Python API Docs | dltHub

Build a Cart-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.

Last updated:

Cart API is a set of REST endpoints provided by e‑commerce platforms to manage a shopper's cart (add, update, remove items, retrieve contents, estimate shipping, and submit the cart as an order). The REST API base URL is `Varies by platform (examples):

  • Shopify Ajax Cart: https://{shop_domain}
  • CS‑Cart: https://{store_domain}/api/
  • Oracle CX Commerce: https://{occe_domain}/ccstore/v1
  • CartRover: https://api.cartrover.com` and Authentication varies by provider: Shopify Ajax Cart uses session cookies (no API key), CS‑Cart and CartRover require HTTP Basic authentication, and Oracle CX Commerce needs a custom X‑CCVisitorId header plus platform credentials..

dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Cart data in under 10 minutes.


What data can I load from Cart?

Here are some of the endpoints you can load from Cart:

ResourceEndpointMethodData selectorDescription
cart/{locale}/cart.jsGETitemsGet current storefront cart (Shopify Ajax). Returns a top‑level object whose items array contains cart items.
cart_shipping_rates/{locale}/cart/shipping_rates.jsonGETshipping_ratesEstimate shipping rates for the current cart (Shopify).
orders_current/ccstore/v1/orders/currentGETRetrieve the incomplete order for the logged‑in visitor (Oracle CX Commerce).
cart_items/ccstore/v1/orders/current/itemsGETitemsList all items in the current Oracle cart.
api_carts/api/cartsGETcartsList all carts (CS‑Cart). Response includes a carts object keyed by cart IDs.
cart_items_cs_cart/api/carts/:id/itemsGETitemsGet items for a specific CS‑Cart cart.
cart_clear/{locale}/cart/clearPOSTClear the Shopify storefront cart.
shipping_async/{locale}/cart/async_shipping_rates.jsonGETshipping_ratesAsynchronous shipping rates endpoint (Shopify).

How do I authenticate with the Cart API?

CartRover requires HTTP Basic authentication: send the API user and API key in the Authorization header (Base64‑encoded "user:key").

1. Get your credentials

  1. Log in to the CS‑Cart admin panel.
  2. Navigate to Administration → API access.
  3. Click Create API key, select the user (typically an admin email), and generate a new key.
  4. Record the admin email (used as username) and the generated API key (used as password) for Basic authentication.
  5. Store these values securely for use in API requests.

2. Add them to .dlt/secrets.toml

[sources.cart_commerce_source] shopify_cart_api_key = "" cs_cart_api_key = "your_api_key_here" cartrover_api_user = "your_api_user" cartrover_api_key = "your_api_key" oracle_cc_visitor_id = "your_visitor_id"

dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.


How do I set up and run the pipeline?

Set up a virtual environment and install dlt:

uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"

1. Install the dlt AI Workbench:

dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex

This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →

2. Install the rest-api-pipeline toolkit:

dlt ai toolkit rest-api-pipeline install

This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →

3. Start LLM-assisted coding:

Use /find-source to load data from the Cart API into DuckDB.

The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.

4. Run the pipeline:

python cart_commerce_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline cart_commerce_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset cart_commerce_data The duckdb destination used duckdb:/cart_commerce.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline cart_commerce_pipeline show

This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.


Python pipeline example

This example loads cart and cart_items from the Cart API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:

import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def cart_commerce_source(cs_cart_api_key, cartrover_api_user, cartrover_api_key, oracle_cc_visitor_id=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "Varies by platform (examples): - Shopify Ajax Cart: https://{shop_domain} - CS‑Cart: https://{store_domain}/api/ - Oracle CX Commerce: https://{occe_domain}/ccstore/v1 - CartRover: https://api.cartrover.com", "auth": { "type": "cs_cart: http_basic; cartrover: http_basic; oracle: header; shopify: none (session cookies)", "cs_cart -> api_key; cartrover -> api_key; oracle -> visitor_id": cs_cart_api_key, cartrover_api_user, cartrover_api_key, oracle_cc_visitor_id, }, }, "resources": [ {"name": "cart", "endpoint": {"path": "{locale}/cart.js", "data_selector": "items"}}, {"name": "cart_items", "endpoint": {"path": "ccstore/v1/orders/current/items", "data_selector": "items"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="cart_commerce_pipeline", destination="duckdb", dataset_name="cart_commerce_data", ) load_info = pipeline.run(cart_commerce_source()) print(load_info)

To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.


How do I query the loaded data?

Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.

Python (pandas DataFrame):

import dlt data = dlt.pipeline("cart_commerce_pipeline").dataset() sessions_df = data.cart.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM cart_commerce_data.cart LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("cart_commerce_pipeline").dataset() data.cart.df().head()

See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.


What destinations can I load Cart data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample value
DuckDB (local, default)"duckdb"
PostgreSQL"postgres"
BigQuery"bigquery"
Snowflake"snowflake"
Redshift"redshift"
Databricks"databricks"
Filesystem (S3, GCS, Azure)"filesystem"

Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.


Troubleshooting

Authentication failures

CS‑Cart: 401 Unauthorized when using incorrect email/API key; ensure Basic auth header contains base64(email:APIkey). CartRover: 401 if api_user/api_key invalid. Shopify Ajax cart: 403 or 404 if using incorrect locale‑aware path.

Rate limiting and throttling

Shopify Ajax shipping_rates endpoint is subject to throttling; return 429 or delayed/empty results; use async prepare_shipping_rates + async_shipping_rates pattern. Aggregators (API2Cart/CartRover) may enforce their own rate limits.

Pagination and response shapes

CS‑Cart list endpoints return object keyed by id under a plural key (e.g., 'products' or 'carts'), not a plain array; Oracle order endpoints may return a single order object; Shopify cart endpoints return a top‑level cart object with an 'items' array — select that key for records.

Common API errors:

  • 401 Unauthorized — invalid/missing credentials
  • 403 Forbidden — insufficient privileges or CORS/CSRF restrictions
  • 404 Not Found — wrong locale path or resource ID
  • 422 Unprocessable Entity — cart errors (Shopify returns status 422 with message "Cart Error" for stock/quantity issues)
  • 429 Too Many Requests — throttling on shipping_rates or aggregator APIs

Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.


Next steps

Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:

  • data-exploration — Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.
  • dlthub-runtime — Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install

Was this page helpful?

Community Hub

Need more dlt context for Cart?

Request dlt skills, commands, AGENT.md files, and AI-native context.