Reporting with Paypal API in Google Script

fondationphardy
Contributor
Contributor

I am using Google script (with Google Spreadsheet) in order to access reporting (list of transactions) with Paypal API.

I managed to get a token using this function :

function getPaypalToken(){
var client_id = "...";
var secret = "..."; 
var options = {
method: "post",
headers : {
"Authorization" : " Basic " + Utilities.base64Encode(client_id + ":" + secret),
"Accept": "application/json",
"Accept-Language": "en_US"
},
payload: {"grant_type": "client_credentials"}
};
var request = UrlFetchApp.fetch("https://api.paypal.com/v1/oauth2/token", options);
var result = JSON.parse(request)
return result.access_token; 
}

I check every box into my app preference (live section) :

Capture.PNG

But when I try that code, I get a PERMISSION_DENIED error...

var token = getPaypalToken()
var headers = {
'Authorization': 'Bearer ' + token,
};
var options = {
"method" : "get",
"headers": headers,
};
var request = UrlFetchApp.fetch("https://api.paypal.com/v1/oauth2/token/userinfo?schema=openid", options)
var result = JSON.parse(request)

THANK YOU for your help !

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.