How to hit the PayPal API

PayPal's REST API runs on https://api-m.sandbox.paypal.com for testing and https://api-m.paypal.com for live. First trade your client id and secret for an access token, then use it as a Bearer token.

Authentication

Create an app under Apps & Credentials to get a client id and secret. The token call sends them as Basic auth (-u, PostTaco's Auth tab); it returns an access_token that the other calls send as {{PAYPAL_ACCESS_TOKEN}}.

Full reference: https://developer.paypal.com/api/rest/

Get an access token

Tokens last about nine hours.

curl -X POST https://api-m.sandbox.paypal.com/v1/oauth2/token \
  -u {{PAYPAL_CLIENT_ID}}:{{PAYPAL_CLIENT_SECRET}} \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d grant_type=client_credentials
Run in PostTaco

Create an order

Returns the order id and an approve link to send the buyer to.

curl -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders \
  -H "Authorization: Bearer {{PAYPAL_ACCESS_TOKEN}}" \
  -H "Content-Type: application/json" \
  -d '{"intent": "CAPTURE", "purchase_units": [{"amount": {"currency_code": "USD", "value": "10.00"}}]}'
Run in PostTaco

Check an order

curl https://api-m.sandbox.paypal.com/v2/checkout/orders/{{ORDER_ID}} \
  -H "Authorization: Bearer {{PAYPAL_ACCESS_TOKEN}}"
Run in PostTaco