I have code that works perfectly when in sandbox mode. However, when switching to live mode, I get a 'Authorization Error' issue. I've double checked that I'm using the right credentials and URLs, but I just get an authentication error. This is the code I'm using to try and access the API: function createPayoutBatch(payoutItems) {
const apiUrl = 'https://api.paypal.com/v1/payments/payouts';
const clientId = 'my-client-id-is-here'
const clientSecret = 'my-secret-is-here'
// PayPal access token
var accessToken = getPayPalAccessToken(clientId, clientSecret, true);
Logger.log("TOKEN " + accessToken) //Access Token is generated properly
var payload = {
"sender_batch_header": {
"sender_batch_id": Utilities.getUuid(),
"email_subject": "Tutoring Payout"
},
"items": payoutItems
};
Logger.log(JSON.stringify(payload))
var options = {
'method': 'post',
'headers': {
'Authorization': 'Bearer ' + accessToken,
'Content-Type': 'application/json',
},
'payload': JSON.stringify(payload),
};
var response = UrlFetchApp.fetch(apiUrl, options);
return response;
} Again, the format of the payload has to be fine because the code works in the Sandbox. I've also double checked that the 'Payouts' checkbox is checked and saved in the API Key setup.
... View more