0

I am using HTTPoison to send request to the Paypal api. Here is the paypal documentation for using its api for logging in: https://developer.paypal.com/docs/log-in-with-paypal/integrate/

When I get the code, and try to exchange it for an access token, I get this error: "{\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}",

Here is how HTTPoison.post!/3 post request:

url = "https://api-m.sandbox.paypal.com/v1/oauth2/token"
headers = [
  Authorization: "Basic #{ClientID}:#{Secret}" 
]
body = "grant_type=authorization_code&code=#{code}"

HTTPoison.post!(url, body, headers)

This shows the a status_code: 401 and {\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}", error.. How can this issue be solved?

user15690889
  • 158
  • 1
  • 5
  • Does this answer your question? [Reddit api oauth authentication elixir](https://stackoverflow.com/questions/57125975/reddit-api-oauth-authentication-elixir) – Adam Millerchip Aug 03 '21 at 13:44

1 Answers1

0

HTTP Basic Authentication requires the value to be base-64 encoded. Try doing that:

Authorization: "Basic " <> Base.encode64("#{ClientID}:#{Secret}")
Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
  • I figured this out like 2 days ago, but thanks for commenting anyways. I have another issue in which you might know how to solve. To authorize an order, you need to pass "PayPal-Request-Id" in the header. But how do you get the paypal request id to authorize and order? This is the paypal documentation and it doesnt provide info on how to get it: https://developer.paypal.com/docs/api/orders/v2/ – user15690889 Aug 03 '21 at 20:41
  • @user15690889 if you solved your problem you should come back here and answer your own question for the benefit of others (or delete the question if you think it's not relevant for others), and prevent people wasting time duplicating your efforts. This isn't a customer support site, but a knowledge-base that's a community effort. – Adam Millerchip Aug 04 '21 at 04:15
  • I came here to do that, but found that you have already answered my question, and thanks for doing so anyways. – user15690889 Aug 04 '21 at 21:33