Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15320

PayPal Adaptive Payments - Preapproval request results in "Invalid request" error

I can't figure out what's happening with my Preapproval HTTP POST request. I'm just trying to do a basic call to PayPal's Adaptive Payments API, the Preapproval call specifically. And the PayPal error 580001 "Invalid request" is not that helpful in itself.

Request Headers (based on my Sandbox's account credentials, which I changed to xxx):

{
  'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON',
  'X-PAYPAL-SECURITY-PASSWORD': 'xxx',
  'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON',
  'X-PAYPAL-SECURITY-SIGNATURE': 'xxx',
  'X-PAYPAL-SECURITY-USERID': 'xx',
  'X-PAYPAL-APPLICATION-ID': 'APP-80W284485P519543T'
}

My request payload (HTTP POST, body encoded in JSON):

{
  "requireInstantFundingSource": "TRUE", 
  "returnUrl": "http://www.google.com/?paypal=ok", 
  "maxTotalAmountOfAllPayments": 1002, 
  "maxNumberOfPaymentsPerPeriod": 1, 
  "endingDate": "2014-03-14T16:49:36+0000", 
  "requestEnvelope.errorLanguage": "en_US", 
  "clientDetails.applicationId": "XXX", 
  "cancelUrl": "http://www.google.com/paypal=cancel", 
  "startingDate": "2013-09-15T16:49:36+0000", 
  "feesPayer": "PRIMARYRECEIVER", 
  "currencyCode": "SEK"
}

The above POST body is posted to:

https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval

Response from Paypal ("prettified" for understanding):

{
  "responseEnvelope": {
    "ack": "Failure", 
    "timestamp": "2013-09-10T09:56:43.031-07:00", 
    "build": "6941298", 
    "correlationId": "26d55e6bfcaa0"
  }, 
  "error": [
    {
      "category": "Application", 
      "domain": "PLATFORM", 
      "severity": "Error", 
      "message": "Invalid request: {0}", 
      "subdomain": "Application", 
      "errorId": "580001"
    }
  ]
}

Any feedback is appreciated.

Upvotes: 0

Views: 1242

Answers (1)

Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15320

OK fixed. How?

Fix #1

The arguments requestEnvelope.errorLanguage and clientDetails.applicationId need to be "JSONified" into objects on their own, such as:

"requestEnvelope": {
    "errorLanguage": "en_US"
}, 

and

"clientDetails": {
    "applicationId": "APP-XXXXXXXXXXXXX"
}, 

respectively.

Fix #2

Date formats; date format should be of the form 2014-03-15T20:14:38.007+00:00 and not 2014-03-14T20:14:38+0000 as I was passing. Note the milliseconds, and the timezone with the colon in the utc offset.

Next time an Invalid request comes up the parameters I'm passing will be the first thing to look at.

Upvotes: 3

Related Questions