Make your first call

To make a PayPal REST request:

Note: You can run the examples listed here directly as-is. However, when creating your own application, be sure to update the OAuth keys in your code with those assigned to your own PayPal app.

Create a PayPal app

Navigate to the My Apps & Credentials page, and log in if necessary. In the REST API Apps section, click Create App to begin the application-creation process. For details about how to create and manage your PayPal applications, see Manage your applications.

When you create an app, PayPal generates a set of OAuth keys for the application (the keys consist of a client_id and secret). These keys are created for both the Sandbox and Live environments.

Tip: To see how the OAuth keys work, run the example in the next step. The example uses a set of dummy keys. To make your first call, paste the example as-is into a Terminal window.

Get an access token

Make a /token call using your application's OAuth keys for the basic authentication values (the keys are the values of your client_id and secret). In the request body, set grant_type to client_credentials. When you run the command, PayPal generates and returns a new access token.

Tip:

  • If you use cURL, supply the OAuth values:
    -u {Client-Id}:{Secret}
    
  • If you use the Postman tool:
    • On the Basic Auth tab, enter the client_id and secret values.
    • Set the username to client_id and the password to secret.
    • On the x-www-form-unlencoded tab, set grant_type to client_credentials.

Example access token request

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
  -H "Accept: application/json" \
  -H "Accept-Language: en_US" \
  -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \
  -d "grant_type=client_credentials"

Tip: If you use Windows, use a Bash shell to make cURL calls. If you do not use cURL, set content-type in the request to application/x-www-form-urlencoded.

Sample response

{
  "scope":"https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*",
  "access_token":"Access-Token",
  "token_type":"Bearer",
  "app_id":"APP-6XR95014SS315863X",
  "expires_in":28800
}

Note: The access token is valid for the number of seconds specified in the expires_in response value. You must have a valid access token to make API requests—request a new token when the current one expires.

Make an API call

With a valid access token in hand, you're ready to make a request to a REST interface. The following call creates a PayPal account payment. The simple request uses only the required input fields.

The access token is an OAuth bearer token, and is included in the header of your requests with the following syntax:

Authorization: Bearer Access-Token

For details on authentication, see How PayPal uses OAuth.

Important: You must supply a valid access token to complete this request (generate a valid token using the example call above).

Example PayPal payment request

curl -v https://api.sandbox.paypal.com/v1/payments/payment \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer Access-Token" \
  -d '{
  "intent":"sale",
  "redirect_urls":{
    "return_url":"http://example.com/your_redirect_url.html",
    "cancel_url":"http://example.com/your_cancel_url.html"
  },
  "payer":{
    "payment_method":"paypal"
  },
  "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      }
    }
  ]
}'

A successful call returns a confirmation of the transaction with the state set to created. You can also confirm the creation of the PayPal transaction using the Sandbox Transactions dashboard.

Be aware that you must complete two additional steps to finalize and capture the PayPal payment. Accept a PayPal payment contains all the details needed to complete the PayPal payment flow. You can also learn how to make payments using our interactive tool.

Learn more

back to top