REST APIs
    Get Started with PayPal REST APIs
    Authentication
    Postman Guide
    API requests
    API responses
    Core Resources
    Overview
    API Integration
    Release Notes
    Add Tracking
    Catalog Products
    Disputes
    Identity
    Invoicing
    Orders
    Partner Referrals
    Payment Experience
    Payment Method Tokens
    Payments
    Payouts
    Referenced Payouts
    Subscriptions
    Transaction Search
    Webhooks Management
    Webhooks
    Overview
    Webhook event names
    Webhooks Events dashboard
    Webhooks simulator
    Integration
    Sandbox
    Overview
    Accounts
    Bulk Accounts
    Card testing
    Codespaces
    PayPal for Visual Studio Code
    Negative Testing
      Test Values
      Request Headers
    Go Live
    Production Environment
    PayPal Application Guidelines
    PayPal Security Guidelines
    Rate Limiting Guidelines
    Idempotency
    Troubleshooting
    Not authorized
    Resource not found
    Unprocessable entity
    Validation error
    Reference
    Currency Codes
    Country Codes
    State & Province Codes
    Locale codes
    Deprecated Resources
    Deprecated resources
    Billing Agreements
    Billing Plans
    Invoicing v1
    Orders v1
    Partner Referrals v1
    Payments v1

Request headers

Note:If you do not use the specific test values, the service returns the actual API responses.

You can use request headers to test the following Payments API and Orders API methods:

  • Payments API v1
    • Create payment
    • Execute approved PayPal payment
  • Payments API v2
    • Show details for authorized payment
    • Capture authorized payment
    • Void authorized payment
    • Show captured payment details
    • Refund captured payment
    • Show refund details
  • Orders API v2
    • Create order
    • Update order
    • Show order details
    • Authorize payment for order
    • Capture payment for order

Set up your development environment

Before you can use request headers to simulate negative responses, you must set up your development environment. After you get a token that lets you access protected REST API resources, you create sandbox accounts to test your web and mobile apps. For details, see Get started.

Then, return to this page to use request headers to simulate negative responses.

Invoke negative testing

1.Enable negative testing.
2.Test API error handling routines.
3.Test with negative testing.

Enable negative testing

REST API apps use a request header to invoke negative testing in the sandbox. This header configures the sandbox into a negative testing state for transactions that include the merchant.

To enable negative testing:

  • Add a key to the PayPal-Mock-Response request header in your API call.

Test API error handling routines

To simulate an error, add a mock_application_codes value that equals the error code to test:
Request headerTypeExample
PayPal-Mock-ResponseJSONmock_application_codes: DUPLICATE_INVOICE_ID

For the available error codes, see Payment API Error Messages and Orders API Error Messages.

Test with negative testing

With a valid access token, you can make REST API calls for negative testing.

Example request

1curl -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders/7WH94211LK834082R/capture -H 'Authorization: Bearer <Access-Token>' -H 'Content-Type: application/json' -H 'PayPal-Mock-Response: {"mock_application_codes": "DUPLICATE_INVOICE_ID"}'

Where:

HeaderValue
Content-Typeapplication/json
AuthorizationBearer $<Access-Token> See get an access token
PayPal-Mock-Responsemock_application_codes: <error_name>

Example response

1{
2 "name": "UNPROCESSABLE_ENTITY",
3 "details": [
4 {
5 "issue": "DUPLICATE_INVOICE_ID",
6 "description": "Duplicate Invoice ID detected. To avoid a potential duplicate transaction your account setting requires that Invoice Id be unique for each transaction."
7 }
8 ],
9 "message": "The requested action could not be completed, was semantically incorrect, or failed business validation.",
10 "debug_id": "70c28ae654da",
11 "links": [
12 {
13 "href": "https://developer.paypal.com/docs/api/orders/v2/#error-DUPLICATE_INVOICE_ID",
14 "rel": "information_link",
15 "method": "GET"
16 }
17 ]
18}
Reference
PayPal.com
Privacy
Support
Legal
Contact