PayPal Payout API REQUIRED_SCOPE_MISSING

richardbuiteman
New Community Member
I am trying to implement payout request using CURL. But I am getting this error: "name":"REQUIRED_SCOPE_MISSING","message":"Access token does not have required scope.","information_link":"https://developer.paypal.com/docs/api/payments.payouts-batch/#errors"

I have already checked on payouts scope in-app settings on developer dashboard.

Here is code:

 

$host = 'https://api.sandbox.paypal.com';
$clientId = 'id';
$secret  = "secret";
$token = '';

function get_access_token($url, $postdata) {
 global $clientId, $clientSecret;
 $curl = curl_init($url); 
 curl_setopt($curl, CURLOPT_POST, true); 
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($curl, CURLOPT_USERPWD, $clientId . ":" . $clientSecret);
 curl_setopt($curl, CURLOPT_HEADER, false); 
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
 curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 
 $response = curl_exec( $curl );
 if (empty($response)) {
     die(curl_error($curl));
     curl_close($curl);
 } else {
     $info = curl_getinfo($curl);
     echo "Time took: " . $info['total_time']*1000 . "ms\n";
     curl_close($curl);
     if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
        echo "Received error: " . $info['http_code']. "\n";
        echo "Raw response:".$response."\n";
        die();
     }
 }
 $jsonResponse = json_decode( $response );
 return $jsonResponse->access_token;
}

function make_post_call($url, $postdata) {
 global $token;
 $curl = curl_init($url); 
 curl_setopt($curl, CURLOPT_POST, true);
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($curl, CURLOPT_HEADER, false);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer '.$token,
    'Accept: application/json',
    'Content-Type: application/json'
    ));

 curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 
 $response = curl_exec( $curl );
 if (empty($response)) {
     die(curl_error($curl));
     curl_close($curl);
 } else {
     $info = curl_getinfo($curl);
     echo "Time took: " . $info['total_time']*1000 . "ms\n";
     curl_close($curl); // close cURL handler
     if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
       echo "Received error: " . $info['http_code']. "\n";
       echo "Raw response:".$response."\n";
       die();
     }
 }
 $jsonResponse = json_decode($response, TRUE);
 print_r($jsonResponse); die;
 return $jsonResponse;
}

echo "\n";
echo "###########################################\n";
echo "Obtaining OAuth2 Access Token.... \n";

$url = $host.'/v1/oauth2/token'; 
$postArgs = 'grant_type=client_credentials';
$token = get_access_token($url,$postArgs);

echo "Got OAuth Token: ".$token;
echo "\n \n";
echo "###########################################\n";
echo "Initiating a Payment with PayPal Account... \n";

$url = $host.'/v1/payments/payouts';
$member_email = "beneficiary email";

$data = array(
  "sender_batch_header" => array(
    "sender_batch_id" => '2542'.time(),
    'email_subject' => 'Withdraw',
    'email_message' => 'You have withdraw from asfd! Thanks for using our service!'
  ),
  "items" => array(
    array(
      "recipient_type" => 'EMAIL',
      'amount' => array(
        'value' => 10.99,
        'currency' => 'USD',
      ),
      'note' => 'Thank You',
      'sender_item_id' => 'A25426',
      'receiver' => $member_email,
    ),
  ),
);

$data = json_encode($data);

$json_resp = make_post_call($url, $data);

foreach ($json_resp['links'] as $link) {
 if($link['rel'] == 'execute'){
  $payment_execute_url = $link['href'];
  $payment_execute_method = $link['method'];
 } else  if($link['rel'] == 'approval_url'){
   $payment_approval_url = $link['href'];
   $payment_approval_method = $link['method'];
  }
}
echo "Payment Created successfully: " . $json_resp['id'] ." with state '". $json_resp['state']."'\n\n";
echo "Please goto <a href='".$payment_approval_url."'>link</a> in your browser and approve the payment with a PayPal Account.\n";
Login to Me Too
3 REPLIES 3

angelleye
Advisor
Advisor
You have to get Payouts enabled specifically on your account before you'll be able to use them. You need to contact PayPal directly about this.
Angell EYE - www.angelleye.com
PayPal Partner and Certified Developer - Kudos are Greatly Appreciated!
Login to Me Too

MTS_Andre
Moderator
Moderator

I confirm that payouts is not enabled on your account. In order to have MassPayments/Payouts enabled on your live account please contact our Customer Service that can give you some more information on that. Alternatively please check this link

Login to Me Too

nehasharma30802
Contributor
Contributor

I am also having this problem. I am using sandbox app credentials and payouts are enabled on that app. But still it is giving REQUIRED_SCOPE_MISSING error. What should I do ?

Login to Me Too

Haven't Found your Answer?

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