Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paypal authentication failure in sandbox

I encounter an issue when I try to use the Paypal sandbox API. I've created my 2 sandbox accounts (the facilitator and the buyer), and I've created my app to get the credentials.

Then, I use the curl example provided by Paypal to get a token :

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
   -H "Accept: application/json" \
   -H "Accept-Language: en_US" \
   -u "my-client-id:my-secret" \
   -d "grant_type=client_credentials"

I get a 200 response, with an "access_token".

Then, I use this access token to get another resource, for example :

curl -v -X GET https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer the-token-received-above"

Then, I get a 401 error : { "name":"AUTHENTICATION_FAILURE", "message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.", "links":[{ "href":"https://developer.paypal.com/docs/api/overview/#error", "rel":"information_link" }] }

I don't understand what I'm doing wrong, since I've followed every step decribed in the Paypal doc (at least, I think I have... probably not)

Thanks for your help

like image 454
Jiji Avatar asked Aug 09 '18 06:08

Jiji


People also ask

How do I get a PayPal Sandbox signature?

Log in to your sandbox PayPal account. Go to Settings (Gear Icon) > Account Settings > API Access. Select NVP/SOAP API integration (Classic) > Manage API Credentials > Request API Signature. You can find API Username, API Password, and API Signature.

What is the difference between PayPal sandbox and live?

PayPal Sandbox is a virtual testing environment that mimics the live PayPal production environment. It works similarly to making an actual PayPal but without using real credit cards or live PayPal accounts. There are 2 different sandbox account types, Personal and Business.


1 Answers

curl -v -X GET "https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer the-token-received-above"

Actually had this exact same issue but didn't know what was wrong with my curl. For me, the issue was I forgot to put "Bearer" in the Authorization section.

For this, you are required to wrap the URL with quotation marks.

like image 146
Alex Avatar answered Oct 14 '22 05:10

Alex