Request Headers

Overview

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 v1 methods:

Prerequisites

Before you can trigger the simulator, you must create a PayPal REST app and get an access token:

1. Create a PayPal app.
When you create an app, PayPal generates a set of OAuth credentials.
2. Get an access token.
Pass the OAuth credentials in a get access token call.
In response, the PayPal authorization server issues an access token.
3. Make REST API calls.
Use the access token for authentication when you make REST API calls.

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:

  • Use the v1/payments/payment or v1/payments/payment/payment_id/execute API endpoint.
  • Add a key to the PayPal-Mock-Response request header in your API call.

Note: You can complete negative testing for only create payment and execute approved PayPal payment.

Test API error handling routines

To simulate an error, add a mock_application_codes value that equals the error code to test:

Request header Type Example
PayPal-Mock-Response JSON
{\"mock_application_codes\": \"MALFORMED_REQUEST\"}

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

Test with negative testing

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

Example request

curl https://api.sandbox.paypal.com/v1/payments/payment/PAY-2Y944451FL143340ELNLU5VA/execute \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer Access-Token" \
  -H "PayPal-Mock-Response: {\"mock_application_codes\": \"MALFORMED_REQUEST\"}"

Where:

Header Value
Content-Type application/json
Authorization Bearer Access-Token
See get an access token.
PayPal-Mock-Response {\"mock_application_codes\": \"error_name\"}

Example response

{
  "name": "MALFORMED_REQUEST",
  "message": "JSON request is malformed.",
  "information_link": "https://developer.paypal.com/docs/api/errors/#validation-errors",
  "debug_id": "a1b2c3d4e5f6g",
  "details": [
  {
    "issue": "Review the JSON request."
  }]
}
Feedback