Onaiggac Onaiggac - 1 year ago 313
reST (reStructuredText) Question

Using Paypal REST API with Classic ASP

I am trying to make a simple call to Paypal API with the follow code:

On error resume next

Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.open "POST", "https://api.sandbox.paypal.com/v1/oauth2/token", False

objHTTP.setRequestHeader "Accept", "application/json"
objHTTP.setRequestHeader "Accept-Language", "en_US"
objHTTP.setRequestHeader "Authorization", "Basic " & Base64Encode("client-id:secret")
objHTTP.send "grant_type=client_credentials"

Response.Write err.description & " | " & err.number

But its returning the error:

The download of the specified resource has failed

I can do this call with de Postman without problem. I am in localhost and Im not using a SSL on my site (dont know if its affect).

Answer Source

To solve my problem I am using the NVP API and now I am doing something like this

Set objHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")
objHTTP.open "POST", "https://api-3t.sandbox.paypal.com/nvp", False

Dim data
data = "USER=" & paypal_user_name &_
"&PWD=" & paypal_psw &_
"&SIGNATURE=" & paypal_signature &_
"&VERSION=204.0" &_
"&RETURNURL=" & return &_
"&CANCELURL=" & cancel &_
"&PAYMENTREQUEST_0_AMT=" & Request.QueryString("val") &_
"&L_PAYMENTREQUEST_0_NAME0=" & Request.QueryString("pac") &_
"&L_PAYMENTREQUEST_0_AMT0=" & Request.QueryString("val") &_

objHTTP.send data

And its working very fine

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download