0

As mentionned in the official documentation extract access token

I want to integrate a paypal sandbox account into my Angular application
but I have encoutered " 400 bad request error "
when I send a rest call to get access token

 connectToPaypalAccount(paypalCode) : Observable<any> {

const headers = new HttpHeaders().set('Authorization' , 'Basic '+this.paypalClientID+':'+this.paypalClientSecret);

  const body = {
  grant_type : 'authorization_code' ,
  code: paypalCode
  }
   return this.http.post('https://api.sandbox.paypal.com/v1/oauth2/token' , body , { headers }); } 
    

i m sure that i have a valid ( clientID , Secret , authorization code ) and it works with postman
see this picture below enter image description here

any help is appreciated

barsawi13
  • 153
  • 3
  • 12
  • Try: `set('Authorization' , 'Basic ' + btoa(this.paypalClientID + ':' + this.paypalClientSecret))`? – Z. Bagley Sep 23 '20 at 23:32
  • Also, if that doesn't work you may need FormData for your body, rather than json: https://stackoverflow.com/a/47560146/7733570 – Z. Bagley Sep 23 '20 at 23:39
  • 1
    i found the solution it s just an invalid body type i must send a **string** type instead of **json** or **formData** `const body ='grant_type=authorization_code&code='+paypalCode;` – barsawi13 Sep 24 '20 at 10:41

0 Answers0