Specify multiple scopes in PayPal RequestPermission API
Asked Answered
H

2

6

Looking at the RequestPermissions API, it says that the scope is supposed to be a string. However, I have been unsuccessful in finding out how to specify more than one scope (specifically EXPRESS_CHECKOUT and REFUND). Comma-separated, semi-colon, and even using their NVP list syntax didn't work. A CURL sample would be greatly appreciated.

Comma-separated example...

curl -s --insecure -H 
"X-PAYPAL-SECURITY-USERID: API_USERNAME" 
-H "X-PAYPAL-SECURITY-PASSWORD: API_PASSWORD" 
-H "X-PAYPAL-SECURITY-SIGNATURE: API_SIGNATURE" 
-H "X-PAYPAL-REQUEST-DATA-FORMAT: NV" 
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV" 
-H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" 
https://svcs.sandbox.paypal.com/Permissions/RequestPermissions -d 
"requestEnvelope.errorLanguage=en_US&scope=EXPRESS_CHECKOUT,REFUND&callback=http://my/callback"

When I make that request, I get back "Invalid request parameter scope with value EXPRESS_CHECKOUT,REFUND"

Heiner answered 16/7, 2012 at 13:43 Comment(0)
H
11

Ok. Found the answer randomly. The scope variables must be set using "scope(0)=SCOPE_1&scope(1)=SCOPE_2..."

So, the cURL request would look like this...

curl -s --insecure -H 
"X-PAYPAL-SECURITY-USERID: API_USERNAME" 
-H "X-PAYPAL-SECURITY-PASSWORD: API_PASSWORD" 
-H "X-PAYPAL-SECURITY-SIGNATURE: API_SIGNATURE" 
-H "X-PAYPAL-REQUEST-DATA-FORMAT: NV" 
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV" 
-H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" 
https://svcs.sandbox.paypal.com/Permissions/RequestPermissions -d 
"requestEnvelope.errorLanguage=en_US&scope(0)=EXPRESS_CHECKOUT&scope(1)=REFUND&callback=http://my/callback"
Heiner answered 16/7, 2012 at 20:21 Comment(5)
Dude, what the heck. PayPal's apis, and documentation are such garbage. Thank you for posting this. If you are in Seattle, I owe you a beer.Captive
Sigh! PayPal api gives such a headache!! Thanks for this! +1Amoebaean
@Heiner : I am owner of my ecommerce website. I have many sellers added there. I am asking that if i put my app credentials (username, password, signature, app id) there and run this script, will this grant the permission from sellers too ? To make an api call like refund api we need permission from sellers too. So will this script grant the permissions from all the sellers including me ?Execution
In this script to whom we are requesting to grant permission for ?Execution
In addition if that can help someone with php to supply multiple scopes it must be an array. Example : $data = array("scope" => array("EXPRESS_CHECKOUT","EXPRESS_CHECKOUT"),"callback" => "url/success.html","requestEnvelope" => array ("errorLanguage" => "en_US" ) ); $payload = json_encode($data);Clingy
P
3

If you're using their JSON API, scope can be an array.

Psephology answered 22/1, 2014 at 23:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.