4

I have this cURL command from paypal developers page:

https://developer.paypal.com/docs/api/get-an-access-token-curl/

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

My question is, how can i convert that cURL command into a http request with angular?

Can you give me an example of how can i do that? Because i am new with angular and i need help with this..

Thanks!

3
  • That's very broad. Were you not able to find any learning resources about making HTTP requests from Angular? Commented Oct 8, 2020 at 20:08
  • What version of angular are you using? Commented Oct 8, 2020 at 20:11
  • @CrisoforoGaspar In the project that i will try to do it is the version 8.3.20 Commented Oct 8, 2020 at 20:17

1 Answer 1

3

The first thing I would do is to figure out what you actually need to make the request. Looks like you have some auth headers that need to be passed and I'm assuming it's a POST request.

You could simplify it by using something like a CURL to Http Request tool to get it into a more familiar format.

TL;DR: Here you go:

    const headers = new HttpHeaders({
      'Accept': 'application/json',
      'Accept-Language': 'en_US',
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic Y2xpZW50X2lkOnNlY3JldA=='
    });
    this.http.post('https://api.sandbox.paypal.com/v1/oauth2/token', 'grant_type=client_credentials', { headers: headers });

this.http would be the reference to your injected HttpClient

Here is a stackblitz. The request turns a 401 so I'm assuming the creds are invalid.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Yes, you need an secret key from your paypal account to do it, but it works for me because i have that, so i have to include result of the conversion into the http header?
Yea, if that gives you an auth token, you want to replace your Authorization header with that token in subsequent API calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.