Question

Follow the instruction in Paypal Developer 'make your first call':

curl 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"

It is working and get the expected result like the instruction states, but I prefer to use ruby curb gem:

require 'curl'

paypal_result = Curl::Easy.http_post("https://api.sandbox.paypal.com/v1/oauth2/token", "grant_type=client_credentials") do |http|
  http.headers['Accept'] = "application/json"
  http.headers['Accept-Language'] = "en_US"
  http.username = "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp"
end

puts paypal_result.body_str

However I got the following:

{"error":"invalid_client","error_description":"The basic auth authorization header cannot be decoded"}

It is an error for sure, but what's wrong with my curb syntax? Any idea?

Was it helpful?

Solution

I can't tell you exactly what's wrong, but I can tell you how to see what's happening. Try putting it into verbose mode, so you can see what data and headers are actually being sent:

curl = Curl::Easy.new

# Make it verbose, prints to stderr
curl.verbose = true

paypal_result = curl.http_post("https://api.sandbox.paypal.com/v1/oauth2/token", "grant_type=client_credentials") do |http|
  # etc.
end

You can compare with the CLI version by using the -v flag.

Hope that helps you discover the difference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top