Here's my code:
$pp = curl_init();
curl_setopt($pp, CURLOPT_URL, "https://api.paypal.com/v1/payments/billing-plans");
curl_setopt($pp, CURLOPT_HEADER, false);
curl_setopt($pp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($pp, CURLOPT_SSLVERSION , 6);
curl_setopt($pp, CURLOPT_POST, true);
curl_setopt($pp, CURLOPT_RETURNTRANSFER, true);
curl_setopt($pp, CURLOPT_POSTFIELDS, "page_size=3&status=ALL&page=1&total_required=yes");
curl_setopt($pp, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer $token"
));
$result_pp = curl_exec($pp);
echo $result_pp;
Here's the error I'm getting:
{"name":"MALFORMED_REQUEST","message":"The request JSON is not well formed.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"b742c35fe6e0e"}
This is the documentation link:
https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_list
Basically just trying to pull a list of all my PayPal subscriptions, but it looks like I'm not sending something in JSON correctly...
Since you are sending a POST
request, the API believes you are attempting to create a billing plan, and that being the case, your post data is expected to be in json form - which it is not.
According to the docs, to list your plans, the request type should be GET
. So you need to add your params in the url:
curl_setopt($pp, CURLOPT_URL, "https://api.paypal.com/v1/payments/billing-plans?page_size=3&status=ALL&page=1&total_required=yes");
And remove these two lines:
curl_setopt($pp, CURLOPT_POST, true);
curl_setopt($pp, CURLOPT_POSTFIELDS, "page_size=3&status=ALL&page=1&total_required=yes");
It's important to understand that many RESTful APIs use the request types to differentiate between actions on the same endpoint. PATCH
, POST
, PUT
, GET
and DELETE
requests may all have different meanings depending on the API.