5

I am trying to implement a curl request in node. In curl you can perform the following POST request:

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

I understand how to set headers and write the data payload using the node http module, but how do i implement -u client_id:client_secret using the http module?

GiveMeAllYourCats
  • 870
  • 18
  • 23
gloo
  • 2,270
  • 2
  • 20
  • 36
  • I think this answer describes the process from the server side. http://stackoverflow.com/a/5957629/2966874 – aembke Mar 20 '14 at 17:58

1 Answers1

2

Currently I do not know nodejs. But as you know how to set the Headers -H from nodejs, I believe I can help you now! -u client_id:client_secret is equivalent to the following one:

-H "Authorization: Basic XXXXXXXXXXXXX"

Here XXXXXXXXXXXXX is the base64 of the string client_id:client_secret. Don't forget the : at the middle of them.

Sabuj Hassan
  • 36,940
  • 12
  • 73
  • 83