Search code examples
phpcurlpaypalpaypal-sandboxpaypal-subscriptions

Paypal unable to LIST AGREEMENT TRANSACTIONS for an agreement id


I am using Paypal Rest API (Billing Plan and Billing Agreement API) to implement subscription payment in my PHP application.

All API working perfectly. Only the api not working that will be used to search transactions between 2 dates for an agreement.

I checked my request, it is same as in official API doc. https://developer.paypal.com/docs/api/payments.billing-agreements#billing-agreements_transactions

I am using PHP and cURL to call api like this:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/billing-agreements/<Agreement-id>/transaction?start_date=2017-06-15&end_date=2017-06-17");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer <My-Access-Token>";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
curl_close ($ch);
echo '<pre>';
print_r($result);
?>

Always getting this response:

{
   name: "MALFORMED_REQUEST",
   message: "The requested resource was not found",
   information_link: "https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST",
   debug_id: "4cf777ecda3b"
}

Plz help,


Solution

  • So i found whats the issue, it is in Paypal API doc, in cURL code i found this:

    Sample Request

    curl -v -X GET https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-1TJ3GAGG82Y9/transaction?start_date=2017-06-15&end_date=2017-06-17 \
    -H "Content-Type:application/json" \
    -H "Authorization: Bearer Access-Token" \
    -d '{}'
    

    but the cURL URL should be https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-1TJ3GAGG82Y9/transactions?start_date=2017-06-15&end_date=2017-06-17

    The /transaction/ should be plural (/transactions/).

    enter image description here