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

630
Views
User Agent missing error in ReactJS fetch api

I am using News API in ReactJS for fetching news using fetch API.

CODE FRAGMENT

const url = `https://newsapi.org/v2/top-headlines?country=in&category=${this.props.category}&pageSize=${this.state.pageSize}&page=${this.state.page}`;
let data = await fetch(url);

But when I run it on the localhost, it gave an error 400 saying:

{status: 'error', code: 'userAgentMissing', message: 'Please set your User-Agent header to identify your application. Anonymous requests are not allowed.'}

When I searched the same on Stack Overflow, I got a link of a similar problem here:

User Agent Missing error when making a get request to an API

Then I added the User-Agent header in the fetch API's argument:

CODE FRAGMENT

headers = new Headers({
        "X-Api-Key": this.apiKey,
        "User-Agent": navigator.userAgent
    });
const url = `https://newsapi.org/v2/top-headlines?country=in&category=${this.props.category}&pageSize=${this.state.pageSize}&page=${this.state.page}`;
let data = await fetch(url, {
            headers: this.headers
        });

But still it shows the same error:

{status: 'error', code: 'userAgentMissing', message: 'Please set your User-Agent header to identify your application. Anonymous requests are not allowed.'}

This error is asking for "User-Agent" in the request header, but it is already there! When I looked into the network section of the chrome browser.

Screenshot of the network section of chrome

So, what's exactly the problem is? And how to solve this issue?

about 4 years ago · Juan Pablo Isaza
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!