MISSING_API_CREDENTIALS error in standard checkout demo

PaulHeft
Contributor
Contributor

I am running the standard checkout demo code from https://developer.paypal.com/integration-builder/. When I click on a payment button (PayPal, or Debit or Credit Card), server.js tries to generate an access token but Node server reports:

   Failed to generate Access Token: Error: MISSING_API_CREDENTIALS
      at generateAccessToken (file:///C:/Users/Owner/server/server.js:23:13)

This error is the result of missing PAYPAL_CLIENT_ID or PAYPAL_CLIENT_SECRET values. Yet my sandbox credentials are in the process.env file, in the same folder as server.js:

PAYPAL_CLIENT_ID=Aafo...
PAYPAL_CLIENT_SECRET=EOH5...

Any idea what I got wrong or am missing? Thanks!

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

vaishnavib
Moderator
Moderator

Good day@PaulHeft,

 

I would like to suggest that you double-check the internal website code and verify the path of the .env file that you are importing. Additionally, I recommend adding console logs to check if the values from the .env file are being fetched correctly.

 

If you still facing an issue, please create a MTS ticket via - https://www.paypal-support.com/s/?language=en_US  with the issue description and error details.

 

Sincerely,

Vaishnavi

PayPal MTS

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

View solution in original post

Login to Me Too
6 REPLIES 6

PaulHeft
Contributor
Contributor

I forgot to mention that I am running NodeJS from nvm on Windows 11 Home.

Login to Me Too

vaishnavib
Moderator
Moderator

Good day, @PaulHeft,

 

Thank you for posting to the PayPal community.

 

Please follow the steps provided in the below detailed guided link to learn about the authentication and how to perform REST API calls :

 

https://developer.paypal.com/api/rest/authentication/

https://developer.paypal.com/api/rest/postman/

 

Important: If the token is not utilized within 24 hours, you will be required to generate a new one.

 

If you still facing the issue, please create an MTS ticket via - https://www.paypal-support.com/s/?language=en_US  with the issue description and error details.

 

Sincerely,

Vaishnavi

PayPal MTS

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

Login to Me Too

PaulHeft
Contributor
Contributor

Thanks, but I don't think that is my problem. I am using the server.js script supplied by PayPal at https://developer.paypal.com/integration-builder/, so I don't think the problem is in requesting the access token.

...

const { PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT = 8888 } = process.env;
const base = "https://api-m.sandbox.paypal.com";
const app = express();

// host static files
app.use(express.static("client"));

// parse post params sent in body in json format
app.use(express.json());

/**
* Generate an OAuth 2.0 access token for authenticating with PayPal REST APIs.
* @See https://developer.paypal.com/api/rest/authentication/
*/
const generateAccessToken = async () => {
  try {
    if (!PAYPAL_CLIENT_ID || !PAYPAL_CLIENT_SECRET) {
      throw new Error("MISSING_API_CREDENTIALS");
    }

    ...

 

My problem starts earlier than the request, at throw new Error() shown above. Somehow the client credentials are not retrieved from the .env file.

Login to Me Too
Solved

vaishnavib
Moderator
Moderator

Good day@PaulHeft,

 

I would like to suggest that you double-check the internal website code and verify the path of the .env file that you are importing. Additionally, I recommend adding console logs to check if the values from the .env file are being fetched correctly.

 

If you still facing an issue, please create a MTS ticket via - https://www.paypal-support.com/s/?language=en_US  with the issue description and error details.

 

Sincerely,

Vaishnavi

PayPal MTS

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

Login to Me Too

PaulHeft
Contributor
Contributor

Thanks, I'll check!

Login to Me Too

PaulHeft
Contributor
Contributor

Aha, the problem involves the filename and location of the .env file.

Where the PayPal Integration Builder directions say "Create a .env file", it wasn't clear to me that it had to be in the root directory, above the server directory.

Also, I mistakenly thought the filename should be "process.env", since I saw that in the server.js script. No, it must be ".env"!

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.