PayPalCart schema. For the full protocol reference, see the Cart API and Complete checkout API reference pages.
Important: To access and use store sync, complete this form to contact the AI team at PayPal and request access.In this guide, you’ll see how to build an API that integrates with PayPal for AI-powered commerce, including:
- Receiving cart requests from PayPal’s Orders v2 API to validate products, calculate taxes, and handle shipping
- Handling updates to a shopping cart, like shipping options and line items, using the Cart API
- Completing orders by processing PayPal payments and fulfilling shipments using the Complete checkout API
Important: Complete catalog creation and ingestion before you complete set up your cart API.
Agentic shopping flow
Before you set up your API, it helps to understand the different roles and steps in the agentic shopping flow.Product discovery
The shopping journey begins when customers express their needs in natural language. The AI agent interprets this intent and searches PayPal’s ingested catalog to find matching products across multiple merchants. For example:- A customer says, “I need a blue t-shirt.”
- The AI agent queries PayPal’s catalog for blue t-shirts.
- PayPal returns product data along with merchant routing information.
- The AI agent presents the options to the customer.
Cart creation and management
After a customer selects products, the AI agent creates and manages the shopping cart through PayPal. This process validates product availability, pricing, and shipping options in real-time with your merchant API. For example:- The customer says, “I’ll take the medium one.”
- The AI agent sends a cart creation request to PayPal.
- PayPal routes the request to your merchant API for validation.
- Your API responds with cart details, including pricing and shipping options.
Checkout
The final step completes the purchase without requiring customers to leave the conversation. PayPal’s Smart Wallet handles payment authentication and processing while the AI agent confirms order details. For example:- The customer says, “Checkout with PayPal.”
- The AI agent initiates the checkout process with PayPal.
- PayPal processes the payment using the customer’s Smart Wallet.
- The AI agent confirms the order and provides delivery information.
Step 1: Handle incoming cart creation from PayPal
When a customer interacts with an AI agent to buy something, PayPal calls your API endpoint, as shown in the following example.Note: This step shows one type of product feed integration. To determine which type of product feed integration is best for your environment, see the Create a product catalog.
Success response (201 created)
Key response fields
| Field | Description |
|---|---|
id | Cart identifier for GET/PUT/PATCH/checkout operations |
ec_token | PayPal payment token (required for checkout completion) that enables PayPal payment for a customer. |
status | Cart state: CREATED INCOMPLETE READY COMPLETED |
validation_issues | Array of problems that need fixing (empty = good) |
Step 2: PayPal handles payment with customer
After receiving a successful cart creation response:- PayPal presents the cart to the customer for approval.
- The customer approves payment using PayPal’s agentic checkout APIs.
- PayPal returns payment approval details to complete the checkout.
- Your API receives the checkout completion request.
Step 3: Your API works with PayPal to handle the order-completion request
After the customer approves payment, PayPal calls your API to complete the order.Success response (200 OK)
Key parameters
| Parameter | Description |
|---|---|
token | The ec_token returned during cart creation |
type | Currently paypal for PayPal payments |
Unified PayPalCart schema
API endpoints
The Cart API provides 3 core endpoints that handle the complete cart lifecycle. Each endpoint serves a specific purpose in the agentic shopping flow.POST /merchant-cartcreates a new cart.PUT /merchant-cart/{id}updates an existing cart.POST /merchant-cart/{id}/checkoutcompletes the checkout process.
Create a cart
UsePOST /merchant-cartto create a new shopping cart with specified items. The cart also can include customer information, such as a shipping address and payment method to use.
Basic cart creation
This example shows how to create a simple cart.Advanced cart creation
A more advanced cart includes additional information, such as customer contact information (customer) and a payment method (payment_method).
Update a cart
UsePUT /merchant-cart/{id} to update an existing cart by replacing its contents with the provided data. Use this endpoint to add or remove items, change quantities, update the shipping address, apply discounts, and so on.
Important: PUT replaces the ENTIRE cart. It removes or resets any fields that you do not include in your request. This is a complete replacement operation, not a merge.Include all current cart data when making changes, as shown in the following example.
Complete checkout
UsePOST /merchant-cart/{id}/checkout to complete the checkout process for a cart. This endpoint finalizes the purchase by processing the payment using the specified payment method.
Cart status fields
The PayPal Cart API uses 3 key status indicators that work together to communicate cart state and validation issues.| Field | Description |
|---|---|
status | Business outcome status (merchant-controlled) |
validation_status | Item-validation and data-validation status |
validation_issues | Specific problems with type classification |
INCOMPLETE, the validation status is REQUIRES_ADDITIONAL_INFORMATION, and several specific validation issues exist.
Business outcome status
The merchant-controlledstatus value indicates the current state of the cart.
| Value | Description |
|---|---|
CREATED | Cart was successfully created and is ready for use |
INCOMPLETE | Cart has issues that need resolution |
READY | Cart is validated and ready for checkout |
COMPLETED | Order is finalized and payment was captured |
Item-validation and data-validation status
Thevalidation-status value indicates whether the cart contents and data are valid fo checkout. A valid transaction meets these requirements:
- All items are available with current pricing.
- Required information is complete (shipping address, customer data, and so on).
- No business rule violations exist.
- The
validation_issuesarray is empty.
validation-status values.
| Value | Description |
|---|---|
VALID | Cart is ready for checkout. |
INVALID | Cart has problems that block checkout. |
REQUIRES_ADDITIONAL_INFORMATION | PayPal requires more data to proceed. |
REQUIRES_ADDITIONAL_INFORMATION, the validation_issues array indicates what information is needed, for example:
- Required fields are missing (shipping address, checkout fields).
- Items and pricing are valid but require additional customer input.
Validation issues
The validation_issues array communicates business logic problems that prevent cart completion but don’t warrant HTTP error codes. These structured error objects help AI agents understand what went wrong and how to fix it, whether that’s suggesting alternative products for out-of-stock items, requesting missing information, or explaining pricing changes. Use these patterns to provide clear, actionable feedback that enables automatic resolution or guides customers to make informed decisions.| Field | Description |
|---|---|
MISSING_FIELD | Required information is missing (shipping address, checkout fields, and so on). |
INVALID_DATA | Provided data is incorrect or invalid. |
BUSINESS_RULE | Business logic violations (out of stock, minimum order, and so on). |
Note: When validation_issues exist, PayPal sends a PUT request with the updated cart state.
Simple validation error (minimal fields)
Complete validation error (all fields)
Examples of how to use the states
To determine when to use each status, see the following table.| Situation | Validation status | Validation issues | Action Required |
|---|---|---|---|
| Order looks good, ready for checkout | VALID | [] (empty) | Proceed to checkout |
| Missing shipping address | REQUIRES_ADDITIONAL_INFORMATION | [{code: "DATA_ERROR", type: "MISSING_FIELD", context: {specific_issue: "MISSING_SHIPPING_ADDRESS"}}] | Collect shipping address |
| Age verification needed | REQUIRES_ADDITIONAL_INFORMATION | [{code: "DATA_ERROR", type: "MISSING_FIELD", context: {specific_issue: "MISSING_CHECKOUT_FIELDS"}}] | Complete age verification |
| Item out of stock | INVALID | [{code: "INVENTORY_ISSUE", type: "BUSINESS_RULE"}] | Remove item or suggest alternatives |
| Price changed | INVALID | [{code: "PRICING_ERROR", type: "BUSINESS_RULE"}] | Customer must accept new price |
| Invalid postal code | INVALID | [{code: "SHIPPING_ERROR", type: "INVALID_DATA"}] | Correct address format |
| Payment declined | INVALID | [{code: "PAYMENT_ERROR", type: "BUSINESS_RULE"}] | Try different payment method |
Common status combinations
| Scenario | HTTP Status | Cart status | validation_status | validation_issues |
|---|---|---|---|---|
| Cart Created Successfully | 201 Created | CREATED | VALID | [] |
| Item Out of Stock | 200 OK | INCOMPLETE | INVALID | [{code: "INVENTORY_ISSUE", type: "BUSINESS_RULE", context: {specific_issue: "ITEM_OUT_OF_STOCK"}}] |
| Missing Shipping | 200 OK | INCOMPLETE | REQUIRES_ADDITIONAL_INFORMATION | [{code: "DATA_ERROR", type: "MISSING_FIELD", context: {specific_issue: "MISSING_SHIPPING_ADDRESS"}}] |
| Ready for Checkout | 200 OK | READY | VALID | [] |
| Order Completed | 200 OK | COMPLETED | VALID | [] |
HTTP status codes
The PayPal Cart API uses a combination of HTTP status codes and cart status fields to communicate the outcome of requests.| Status | Description | Response content | Action |
|---|---|---|---|
201 Created | Cart created successfully | Full cart object and the ec_token value | Proceed to payment. |
200 OK | Operation was successful | Full cart object | Check the status field. |
200 OK with validation_issues | Specific problems prevent PayPal from completing the transaction. | Full cart object and the validation_issues array | Fix the issues in the validation_issues array. |
400 Bad Request | Invalid request format or missing parameters | Error details | Fix the request format. |
404 Not Found | Cart doesn’t exist | Error details | Use a valid cart ID. |
500 Server Error | System problem | Error details | Retry later or contact technical support. |
Business logic issues
Use200 OK for business scenarios that AI agents can understand and potentially resolve:
- Cart validation issues (out of stock, price changes)
- Missing required information (shipping address, checkout fields)
- Payment processing issues (declined payments, business rules)
Technical issues
Use proper HTTP error codes for technical problems. For the complete list of error codes, see HTTP status codes.Example scenario
Imagine a simple customer interaction where an AI agent helps a customer find and purchase a blue t-shirt.1. Customer begins a product search
Customer: “I need a medium blue t-shirt” AI Agent: processes intent and searches inventory AI Agent: creates cart through PayPal, orchestrating with the merchant’s API
2. PayPal Cart API returns cart information
AI agent: “I found the perfect blue t-shirt in medium! $25 total. Ready to check out?“
3. AI completes checkout
AI Agent: “Ready to check out with PayPal?” Customer: “Yes, go ahead.” AI Agent: seamlessly handles PayPal Smart Wallet approval (no redirect required).
AI Agent: “Order confirmed! Your t-shirt will arrive on Tuesday.”
Customer information availability
This table explains what customer information is available at each stage of the transaction life cycle.| Transaction stage | Information availability |
|---|---|
| Initial cart creation | For anonymous shopping, customer information could be absent. |
| After PayPal checkout approval | Full customer information is available in the checkout completion request. |
| Returning customers | Full customer information might be available, depending on the user’s account setup. |
Authentication with PayPal-supplied JWT tokens
- PayPal-issued: PayPal generates and manages the tokens.
- Request authentication: Every API call includes the token in the authorization header.
- Merchant identification: Tokens contain your merchant ID and permissions.
- Security verification: Verify token signature using PayPal’s public keys. See Verify token.
Receive token in the authorization header
Verify token
- Parse Authorization header:
"Bearer \<token\>". - Verify token signature using PayPal public keys.
- Validate token expiration.
- Check required scopes, such as
"cart"or"complete".
PayPal Orders API integration pattern
Behind the scenes, the PayPal Cart API integrates with PayPal’s Orders API v2 to manage payment tokens and process transactions. Understanding this relationship helps you implement proper payment handling. When implementing the Cart API, merchants must integrate with PayPal Orders API v2 to handle payment tokens and order updates. The following table explains when to create (POST) or update (PATCH) a cart.
| Scenario | PayPal Orders Action | Reason |
|---|---|---|
| Initial cart creation. | POST /v2/orders | Create new payment context |
| Add or remove items. | PATCH /v2/orders/{id} | Update totals |
| Apply or remove coupons. | PATCH /v2/orders/{id} | Update totals |
| Update shipping address. | PATCH /v2/orders/{id} | Update shipping + tax |
| Change quantities. | PATCH /v2/orders/{id} | Update totals |
| Create a fresh payment context when a payment token expires. | POST /v2/orders | Create fresh payment context |
| Create a new cart after checkout. | POST /v2/orders | New transaction |
Examples
The following code snippets illustrate how to implement cart creation and updates.Cart creation with an order
Cart update with an order update
Error handling
Effective error handling is critical for maintaining a smooth shopping experience. The API provides rich error context that enables AI agents to resolve issues automatically or guide customers to resolution. Instead of handling dozens of specific error cases, focus on these essential patterns:- Can you fix this automatically? If you can fix it, fix it for them.
- Can the customer fix this? If you can’t fix it for them, show them how to fix it.
Error categories
| Category | Description |
|---|---|
INVENTORY_ISSUE | Stock, availability, back-orders, discontinued items |
PRICING_ERROR | Price changes, discounts, tax calculation, currency issues |
SHIPPING_ERROR | Address validation, delivery restrictions, shipping zones |
PAYMENT_ERROR | Payment limits, currency support, processor issues |
DATA_ERROR | Field validation, format issues, required fields |
BUSINESS_RULE_ERROR | Account restrictions, compliance, regional limits |
Error types
| Type | Description |
|---|---|
MISSING_FIELD | Need more info (address, checkout fields) |
INVALID_DATA | Data validation failed |
BUSINESS_RULE | Business logic violation, such as inventory issues |
Common error pattern
Inventory and stock management errors
Inventory issues are among the most common errors in e-commerce. These examples show how to handle out-of-stock scenarios, back-orders, and discontinued products gracefully.Out of stock with alternatives
Back-order scenario
Discontinued product
Pricing and financial errors
Price changes can occur between cart creation and checkout. These error patterns help you handle pricing discrepancies transparently while maintaining customer trust.Price change during checkout
Shipping and address errors
Address validation ensures successful delivery while preventing fraud. These examples demonstrate handling invalid addresses, PO Box restrictions, and shipping limitations.Invalid shipping address
PO box restrictions
Geographic and legal restrictions
Some products or merchants have regional restrictions due to regulations or business policies. These errors help communicate limitations clearly to customers.Regional sales restrictions
System and store errors
Temporary system issues require special handling to maintain customer relationships. These patterns show how to communicate maintenance windows and system unavailability.Store maintenance mode
Error handling implementation strategy
When implementing error handling for the PayPal Cart API, use the following guidelines to determine appropriate HTTP status codes and error responses.200 OK + validation_issues
- Inventory changes (out of stock, back-ordered)
- Price changes during checkout
- Payment processing issues that can be resolved
- Geographic restrictions
- Discount validation failures
- Customer account issues
- Address validation problems
422 Unprocessable entity
Use this error code when anyvalidation_issue prevents you from creating a cart. For example, if you do not create a cart for an OUT_OF_STOCK issue, you can send a 422 Unprocessable Entity error with details about the error in the body.
See the API Spec for how to format errors.
400 Bad request
- Invalid JSON format
- Missing required fields (for example, the
itemsarray) - Invalid field types or formats
- Malformed request structure
- Invalid cart ID format (for example, it doesn’t match an expected pattern, such as
"CART-[A-Z0-9]+")
404 not found
- Cart ID doesn’t exist in merchant’s system (well-formed ID but not found)
- Invalid endpoint paths
Cart retrieval error handling
These examples useGET /merchant-cart/{cartId}.
Example: Invalid cart ID format (400 response)
500 internal server error
- System failures
- Database connectivity issues
- Payment processor unavailable
- Unexpected server errors
Error context best practices
- Provide Rich Context: Include all relevant information for smart resolution.
- Customer-Friendly Messages: Write user_message for end customers.
- Technical Details: Include technical message for developers.
- Resolution Guidance: Always provide actionable next steps.
- Cost Impact: Show financial implications of resolution options.
- Time Estimates: Provide realistic timeframes for resolutions.
AI agent considerations for errors
Many errors are well-suited for AI agents to handle them autonomously:- Auto-applicable actions: AI can resolve without human intervention.
- Priority guidance: Immediate action is required.
- Context-rich: The system has enough information for intelligent decision making.
- Resolution metadata: The system helps AI choose best resolution.
Resolution action types
| Action | Use Case | Auto-applicable |
|---|---|---|
ACCEPT_NEW_PRICE | Price increases | No |
ACCEPT_BACK_ORDER | Inventory delays | Depends on customer preference |
SUGGEST_ALTERNATIVE | Out of stock items | Yes |
UPDATE_ADDRESS | Address validation | Yes (if correction available) |
REMOVE_ITEM | Restriction violations | Depends on item importance |
SPLIT_ORDER | Payment limits | Yes |
CONTACT_SUPPORT | Complex issues | No |
RETRY_LATER | Temporary failures | Yes |
Advanced use cases
Beyond basic cart operations, the API supports sophisticated scenarios like gift cards and location-based services. These examples demonstrate advanced integration capabilities.Gift cards
Geographic coordinates
Some merchants offer location-based services that require precise geographic positioning beyond standard postal addresses. The Cart API supports optional latitude/longitude coordinates to enable features like local inventory checking, distance-based pricing, delivery radius validation, and enhanced shipping calculations. This geographic data operates independently from shipping addresses, allowing you to provide location-aware commerce experiences while maintaining clean separation between postal and coordinate data.Latitute and longitude support strategy
Geographic coordinates are optional. It is designed for merchants who can provide enhanced location services. Geographic coordinates are provided in a separategeo_coordinates field, distinct from the shipping_address object. This clean separation allows:
- Postal addresses to remain focused on standard shipping data
- Geographic coordinates to provide precise location enhancement
- Independent handling of address vs. coordinate data
- Graceful degradation when coordinates aren’t supported
Geographic fields
latitude&longitude: Precise WGS84 coordinates in decimal degreessubdivision: Administrative division (state, province, region) using ISO 3166-2 formatcountry_code: ISO 3166-1 alpha-2 country code for the coordinate location
- US:
subdivision: "CA"(California),country_code: "US" - Canada:
subdivision: "ON"(Ontario),country_code: "CA" - UK:
subdivision: "ENG"(England),country_code: "GB"