Curl -u with http package

Hello,

I want to get this result with the http package. but I don’t know how to use the -u paramter with the http package.

-u, --user USER[:PASSWORD] Server user and password

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"

can anybody help me with this?

thanks

Check out the docs for the http package, specifically the auth parameter:

You would use it like this:

HTTP.post("https://api.sandbox.paypal.com/v1/oauth2/token", {
  auth: `${client_id}:${secret}`,
  params: { "grant_type": client_credentials },
  headers: {
    "Accept-Language": "en_US",
    "Accept": "application/json"
  }
});

This is what I’ve got:

HTTP.post("https://api.sandbox.paypal.com/v1/oauth2/token", {
  auth: `${client_id}:${secret}`,
  params: { "grant_type": "client_credentials" },
  headers: {
    "Accept-Language": "en_US",
    "Accept": "application/json"
  }
  }, function( error, response ) {
  if ( error ) {
    console.log( error );
  } else {
    console.log( response );
  }
});

But I’m getting this error:

POST https://api.sandbox.paypal.com/v1/oauth2/token 401 (Unauthorized)
Error: failed [401] {"name":"AUTHENTICATION_FAILURE","message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.","links":[{"href":"https://developer.paypal.com/docs/api/overview/#error","rel":"information_link"}]}
    at Object.exports.makeErrorByStatus (http.js?hash=021da52f029416901f37e5c36569c737c737bcb9:261)
    at XMLHttpRequest.xhr.onreadystatechange (http.js?hash=021da52f029416901f37e5c36569c737c737bcb9:211)

Regarding the error message, there is something wrong how the credentials are passed. So what it the right way to pass the credentials?