Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to make network call with empty body #1816

Open
Nanagoud007 opened this issue May 15, 2024 · 0 comments
Open

Not able to make network call with empty body #1816

Nanagoud007 opened this issue May 15, 2024 · 0 comments
Labels

Comments

@Nanagoud007
Copy link

<!i am making post request to payment gate way with no body using default import of node. ES6 -->

Reproduction
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const genrateNiAccessToken = async () => {
const NIPAYMENTGATEWAYURL = 'https://api-gateway.ngenius-payments.com';
const networkPayPayAccessTokenUrl = ${NIPAYMENTGATEWAYURL}/identity/auth/access-token;

try {
const NIAPIKEY = 'your_api_key_here'; // Fill in your actual API key
const tokenResponse = await fetch(networkPayPayAccessTokenUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/vnd.ni-identity.v1+json',
'Authorization': Basic ${NIAPIKEY},
},
// No need for body if no data is being sent
});

if (!tokenResponse.ok) {
  console.log("Token response not OK:", tokenResponse.status);
  return null;
}

const responseData = await tokenResponse.json();
console.log("Token response data:", responseData);
return responseData;

} catch (error) {
console.error("Error fetching token:", error);
return null;
}
};

genrateNiAccessToken();

Steps to reproduce the behavior:

  1. run the above code snippet

Expected behavior

Screenshots

Node JS

software version
node-fetch ^3.3.2
node 18.0.0
npm 9.2.7
Operating System Ubuntu

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant