login about faq

Hi all,

I am having a problem adding credentials to a http request for the new Palpal Api. I followed the example code with no luck. Below is the code and log.

Thanks,
-- Erik

Set oReq = Server.CreateObject("Chilkat_9_5_0.HttpRequest")
With oReq
  .HttpVerb = "POST"
  .Path = "/v1/oauth/token"

  .AddHeader "Accept", "application/json"
  .AddHeader "Accept-Language", "en_US"

  .LoadBodyFromString "grant_type=client_credentials", "utf-8"

End With

Set oHttp = Server.CreateObject("Chilkat_9_5_0.Http")
With oHttp
  .UnlockComponent "INSURAHttp_...."
  .Login = "AekbqBDNxY8bbkVdWCxxxxxxx"
  .Password = "ECkbMxA-Hk0ptplRDnMUxxxxxxxxxxx"
  .SessionLogFileName = Server.MapPath("./http.log")

End With

Set oResp = oHttp.SynchronousRequest("https://api.sandbox.paypal.com", 443, 1, oReq)

---- Sending ----
POST /v1/oauth/token HTTP/1.1
Accept: application/json
Accept-Language: en_US
Host: api.sandbox.paypal.com
Content-Length: 29

grant_type=client_credentials

---- Received ----
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=247
Paypal-Debug-Id: e3595dbc3c85c
Content-Type: application/json
Content-Length: 0
Date: Wed, 10 Sep 2014 20:28:56 GMT

Curl Example that I am trying to copy

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
  -H "Accept: application/json" \
  -H "Accept-Language: en_US" \
  -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \
  -d "grant_type=client_credentials"

asked Sep 10 '14 at 16:35

emartinson's gravatar image

emartinson
148162030

edited Sep 11 '14 at 19:41


I got it to work, here is the final code. There is one exception that I do not know if it is a bug or feature. If I call SynchronousRequest the path from the request object is used. If I call PostUrlEncoded, the path of the request object is ignored. I added the path to the url parameter of PostUrlEncoded.

Set oReq = Server.CreateObject("Chilkat_9_5_0.HttpRequest")
With oReq
  .HttpVerb = "POST"
  .Path = "/v1/oauth2/token"

.AddHeader "Accept", "application/json"
.AddHeader "Accept-Language", "en_US"
.AddHeader "HOST", "api.sandbox.paypal.com" 'Sandbox
.LoadBodyFromString "grant_type=client_credentials", "utf-8"

End With

Set oHttp = Server.CreateObject("Chilkat_9_5_0.Http")
With oHttp
  .UnlockComponent "INSURAHttp_xxxxxxxxxxxx"
  .BasicAuth = 1
  .Login = "AQAn8hBsRWHjduM_xxxxxxxxxxxxxx"
  .Password = "ECDXwBBABT1pxxxxxxxxxxxxxxxxxxxxxw"
  .SessionLogFileName = Server.MapPath("./http.log")

End With

Set oResp = oHttp.PostUrlEncoded("https://api.sandbox.paypal.com/v1/oauth2/token", oReq)

Result form log:

---- Sending ----
POST /v1/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Accept-Language: en_US
Authorization: Basic QVFBbjhoQnNSV0hqZHVNX291....==
Host: api.sandbox.paypal.com
Content-Length: 29

grant_type=client_credentials

---- Received ----
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava4.slc.paypal.com;threadId=256
Paypal-Debug-Id: d14f745943975
SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=92&TopLevelTxnStartTime=1486724460e&Host=slcsbidensectoken502.slc.paypal.com&pid=16915
Date: Thu, 11 Sep 2014 23:55:03 GMT
Content-Type: application/json
Content-Length: 286

{"scope":"openid https://api.paypal.com/v1/pa.....43T","expires_in":28800}
link

answered Sep 11 '14 at 20:08

emartinson's gravatar image

emartinson
148162030

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×186
×11
×9
×2
×1

Asked: Sep 10 '14 at 16:35

Seen: 1,139 times

Last updated: Sep 11 '14 at 20:08

powered by OSQA