paypal-examples / paypal-dev-support

Resources and guidance on how to engage with the developer community & the PayPal Developer Tools team.
1 stars 2 forks source link

[Bug]: REST Api doc curl examples do not work in Windows #9

Open 8ctopus opened 1 year ago

8ctopus commented 1 year ago

Contact Details

hello@octopuslabs.io

Describe the Issue

curl examples do not work on Windows. Here's an example taken from the documentation:

https://developer.paypal.com/api/rest/authentication/
curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token"\
 -u "CLIENT_ID:CLIENT_SECRET"\
 -H "Content-Type: application/x-www-form-urlencoded"\
 -d "grant_type=client_credentials"

Copy and pasting this in a Windows command line leads to the following output:

K:\downloads>curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token"\
*   Trying 199.232.169.35:443...
* Connected to api-m.sandbox.paypal.com (199.232.169.35) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
* using HTTP/1.1
> POST /v1/oauth2/token\ HTTP/1.1
> Host: api-m.sandbox.paypal.com
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Connection: keep-alive
< Content-Length: 435
< Content-Type: text/html;charset=utf-8
< Server: nginx
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Content-Language: en
< Paypal-Debug-Id: 45d637c97df00
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Accept-Ranges: bytes
< Via: 1.1 varnish, 1.1 varnish
< Edge-Control: max-age=0
< Date: Tue, 26 Sep 2023 03:58:58 GMT
< X-Served-By: cache-lhr7327-LHR, cache-par-lfpg1960041-PAR
< X-Cache: MISS, MISS
< X-Cache-Hits: 0, 0
< X-Timer: S1695700738.861618,VS0,VE482
< Vary: Accept-Encoding
<
<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1></body></html>* Connection #0 to host api-m.sandbox.paypal.com left intact

K:\downloads> -u "CLIENT_ID:CLIENT_SECRET"\
'-u' is not recognized as an internal or external command,
operable program or batch file.

K:\downloads> -H "Content-Type: application/x-www-form-urlencoded"\
'-H' is not recognized as an internal or external command,
operable program or batch file.

K:\downloads> -d "grant_type=client_credentials"

Correct output gets displayed if \ is replaced by ^

curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" ^
 -u "CLIENT_ID:CLIENT_SECRET" ^
 -H "Content-Type: application/x-www-form-urlencoded" ^
 -d "grant_type=client_credentials"
K:\downloads>curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" ^
More?  -u "CLIENT_ID:CLIENT_SECRET" ^
More?  -H "Content-Type: application/x-www-form-urlencoded" ^
More?  -d "grant_type=client_credentials"
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 199.232.169.35:443...
* Connected to api-m.sandbox.paypal.com (199.232.169.35) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
* using HTTP/1.1
* Server auth using Basic with user 'CLIENT_ID'
> POST /v1/oauth2/token HTTP/1.1
> Host: api-m.sandbox.paypal.com
> Authorization: Basic Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ=
> User-Agent: curl/8.0.1
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 29
>
< HTTP/1.1 401 Unauthorized
< Connection: keep-alive
< Content-Length: 77
< Content-Type: application/json
< Server: nginx
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Paypal-Debug-Id: 1cf300fcf12d3
< Pragma: no-cache
< X-Paypal-Token-Service: IAAS
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Accept-Ranges: bytes
< Via: 1.1 varnish, 1.1 varnish
< Edge-Control: max-age=0
< Date: Tue, 26 Sep 2023 04:17:49 GMT
< X-Served-By: cache-lhr7370-LHR, cache-par-lfpg1960057-PAR
< X-Cache: MISS, MISS
< X-Cache-Hits: 0, 0
< X-Timer: S1695701869.999422,VS0,VE594
< Vary: Accept-Encoding
<
{"error":"invalid_client","error_description":"Client Authentication failed"}* Connection #0 to host api-m.sandbox.paypal.com left intact

Steps To Reproduce

See above

What type of Operating System are you seeing the problem on?

Windows

What type of browser are you seeing the problem on?

N/A

Screenshots or Videos

No response

Code to produce this issue.

No response

devchristina commented 1 year ago

Sent this to the team to triage.

devchristina commented 1 year ago

@8ctopus -- Here's what I'm getting from the team:

It's true that curl samples need to adjusted for terminals of idiosyncratic operating systems, such as Windows. Currently our documentation site does not have the capability to toggle & select different OS to view the samples. If you don't want to adjust the samples, the suggestion would be to use WSL to run them.

In your opinion, is this a nice feature to have or do you find that other companies are providing this type of capability?

8ctopus commented 1 year ago

IMO, the samples should work whatever platform the developer is using and it's not that it is not a problem that is hard to fix. You re just telling developers to use your competitors instead. There are way too many bugs at the moment as you have seen from the issues I have posted in the last week.

devchristina commented 1 year ago

We don't see that competitors are doing it any different. None the less, we take this feedback seriously and I'll challenge the team to come up with a solution. You've helped tremendously this week with the bugs and while true to say it's been a lot, your effort to call them out and notify us is truly appreciated.