The same request returns successfully in python, as in 

conn = http.client.HTTPConnection("api,sandbox,paypal,com")

payload = "grant_type=client_credentials"

headers = {
    'Content-Type': "application/x-www-form-urlencoded",
    'Authorization': "Basic 
QVF5YS10UmFKUlIzTVVHQVY2MTg4OVl5eEc1MFdmUlhhZEtLYWZqU0hpRUZxT195WGRFNWR3T01BdC1NeklMeU54S2Y3XzNHM3JuYmx1aWE6RVBYQjUxREhLY3RqemtzUzJqUUhwbWVFckdRWnpwalRxZmZGZ3VhZlRUNm1lVFRmTF9VNG1MYVF4MDFFLVRXcEw0MmlHVkNxSkFIQmNSYkE=",
    'User-Agent': "PostmanRuntime/7.15.0",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Postman-Token': 
"1b42b98e-5c36-4d2b-958c-91463fef648c,269500a1-20d2-479f-90fb-fb2706a7475a",
    'Host': "api.sandbox.paypal.com",
    'accept-encoding': "gzip, deflate",
    'content-length': "29",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

conn.request("POST", "v1,oauth2,token", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8”))



The result is 



{"scope":"https://uri.paypal.com/services/invoicing 
https://uri.paypal.com/services/disputes/read-buyer 
https://uri.paypal.com/services/payments/realtimepayment 
https://uri.paypal.com/services/disputes/update-seller 
https://uri.paypal.com/services/payments/payment/authcapture openid 
https://uri.paypal.com/services/disputes/read-seller 
https://uri.paypal.com/services/payments/refund 
https://api.paypal.com/v1/vault/credit-card 
https://api.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts 
https://api.paypal.com/v1/vault/credit-card/.* 
https://uri.paypal.com/services/subscriptions 
https://uri.paypal.com/services/applications/webhooks","access_token":"A21Ajrtihjrujhirjhiojheioji5wt83qyt78y3785y7845FEWRGFERHGIEGEWGzpuO0xg_I75pmqFAoSIuArLnfQIoBPdJLdyKSgig","token_type":"Bearer","app_id":"APP-876543FSDFSFP519543T","expires_in":32400,"nonce":"2019-11-15T16:00:40ZlUhzF8DCS6fFc88NwHf-BjiJZv6_DdVG4J8MU5VaHC0"}




> On Nov 15, 2019, at 14:48, Iuri Sampaio <i...@iurix.com> wrote:
> 
> So far, I added the line 
> 
> ns_set update $requestHeaders "Authorization" "Basic $auth_base64"
> 
> which is using 
> set auth_base64 [base64::encode “********”]
> 
> and the results are
> 
> [15/Nov/2019:13:19:55][450.7f7a7d7fa700][task:tclhttp] Notice: HttpTaskRecv: 
> connection probably closed by server (url 
> https://api.sandbox.paypal.com/v1/oauth2/token 
> <https://api.sandbox.paypal.com/v1/oauth2/token>)
> [15/Nov/2019:13:19:55][450.7f7a65ffb700][-conn:evex:88:31735-] Notice: status 
> code 0
> [15/Nov/2019:13:19:55][450.7f7a65ffb700][-conn:evex:88:31735-] Notice: reply 
> [
> 
> 
>> On Nov 15, 2019, at 12:21, Iuri Sampaio <i...@iurix.com 
>> <mailto:i...@iurix.com>> wrote:
>> 
>> What would be the argument/switch to convert the option -u, from CURL 
>> command, to ns_http command?
>> 
>> curl -v https://myhost.com/oauth2/token <https://myhost.com/oauth2/token> \
>>    -H "Accept: application/json" \
>>    -H "Accept-Language: en_US" \
>>    -u "client_id:secret" \
>>    -d "grant_type=client_credentials"
>> 
>> 
>> 
>> Reading ns_http documentation I was not able to figure that out.  
>> https://naviserver.sourceforge.io/n/naviserver/files/ns_http.html#section3 
>> <https://naviserver.sourceforge.io/n/naviserver/files/ns_http.html#section3>
>> 
>> 
>> 
>> set url "https://myhost.com/v1/oauth2/token 
>> <https://myhost.com/v1/oauth2/token>"
>> set requestHeaders [ns_set create]
>> set replyHeaders [ns_set create]
>> 
>> ns_set update $requestHeaders "Content-Type" "application/json"
>> ns_set update $requestHeaders "Accept" "application/json"
>> ns_set update $requestHeaders "Accept-Language" "en_US"
>> 
>> set data "grant_type=client_credentials"
>> 
>> 
>> set result [ns_http queue -method POST \
>>                 -headers $requestHeaders \
>>                 -timeout 10.0 \
>>                 -body $data \
>>                 $url]
>> ns_http wait -result R -headers $replyHeaders -status S $result
>> 
>> 
>> 
>> 
>> Best wishes,
>> I
>> _______________________________________________
>> naviserver-devel mailing list
>> naviserver-devel@lists.sourceforge.net 
>> <mailto:naviserver-devel@lists.sourceforge.net>
>> https://lists.sourceforge.net/lists/listinfo/naviserver-devel
> 

_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to