Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
TypeError on fetch request on "e-raktakosha" web site api

I am new to javascript. I was trying to make an api call. My code

const options = {
  method: 'GET',
  headers: {
    Authorization: 'Basic dW5kZWZpbmVkOnVuZGVmaW5lZA==',
    'content-type': 'application/json',
  }
};
fetch(
  'https://www.eraktkosh.in/BLDAHIMS/bloodbank/nearbyBB.cnt?hmode=GETNEARBYSTOCKDETAILS&stateCode=21&districtCode=378&bloodGroup=all&bloodComponent=11&lang=0',
  options
)
  .then((response) => response.json())
  .then((response) => console.log(response))
  .catch((err) => console.error(err));

but I encountered with an error saying

Error: Failed to fetch
  1. This api call works perfectly with Hoppscotch
  2. If I try to hit the url right on my url bar, it also works fine.

Any help is strongly appreciated. Thank you from Manoranjan

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Please don't use body with a get request. The GET request is purely meant to collect back data from server, which allows you to sent Queries, not data on the request. Just remove body:'false' or use body:false. The best way is to remove the body from your request so unexpected input is not sent via this GET request.

about 4 years ago · Juan Pablo Isaza Report

0

As other People already mentioned, you can't pass a Body when doing a GET HTTP call, instead you can pass Query Params

Notice this part on the URL

hmode=GETNEARBYSTOCKDETAILS&stateCode=21&districtCode=378&bloodGroup=all&bloodComponent=11&lang=0

Still looking into the code it seems the server have a cors policy, look at this sandbox

See this codesandbox -> https://codesandbox.io/s/peaceful-mcclintock-exuzol?file=/src/index.js

Summary:

  • GET accept body/payload but it could cause errors, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET

  • Using the Web API (new headers, new request) for doing the HTTP call

GET warning of body/payload usage

It is better to just avoid sending payloads in GET requests.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!