Ask coding questions

← Back to all posts
How to fetch replit websites without getting Cloudflare Errors?
DREWNOLT (27)

I am trying to make a replit API using node-fetch in node.js, but I only get Cloudflare errors. How do I fix this?

Comments
hotnewtop
RayhanADev (1949)

Hello @DREWNOLT !

Pinging @ch1ck3n @EpicGamer007 @RicksNext to help ya'll out too ;D
Okay so you're trying to query the replit API at https://replit.com/graphql I presume?
I built a Replit API a while back and had to revamp it recently to make it work.

My solution

Instead of bypassing the Cloudflare, send requests to staging.replit.com/graphql. Use the X-Requested-With header (any value) and Referrer header (https://replit.com/). That will fix all your problems.

programmeruser (571)

@RayhanADev make sure that your User-Agent doesn't look suspicious either, set it to something like Mozilla/5.0 (credits to @firefish).
Example: https://repl.it/@programmeruser/graphql

RayhanADev (1949)

@programmeruser yea true. I never had that problem but it's good to cross all your x's anyways :)

EpicGamer007 (1633)

@DREWNOLT ok, so you CAN DO IT WITH NODEJS. There is an api client made by @RayhanADev for thh graphql api made in nodejs which can be found here. Additionally, you can make requests to https://replit.com/data/profiles/{username} in nodejs but with https requests. Check out this. This is the code from it:

router.get("/user-info", (req, res) => {
	if (!req.query.username) {
		res.render("error", errors[405]);
		return;
	}

	// const vals = userInfoCache.map(v => v.username.toLowerCase() === req.query.username.toLowerCase());
	const vals = userInfoCache.filter(v => v.username.toLowerCase() === req.query.username.toLowerCase());

	if (vals.length > 0) {
		res.json(vals[0]);
		return;
	}

	https.get(
		`https://replit.com/data/profiles/${req.query.username}`,
		(dataRes) => {
			if ( dataRes.statusCode < 200 || dataRes.statusCode > 299 ) {
				res.render("error", errors[500]);
				return;
			}

			let data = "";
			dataRes.on("data", (chunk) => {
				data += chunk;
			});

			dataRes.on("end", () => {
				vals.push(data);

				res.json(data);
			});
		}
	).on("error", () => {
		res.render("error", errors[404]);
	});
});

(this code is with express so thats what all the fancy stuff is for. the main stuff is after the https.get())

First, you need to import the https module. then make the request.

Hope this helped ;)

RicksNext (0)

Have you tried adding headers like User-Agent, Host, etc to pretend that the request you're making is coming from a browser?

RicksNext (0)

@DREWNOLT From the tests I made, adding the "Referer" and "Origin" headers in the fetch headers thing (the values for both can be the address of the page youre trying to access) fix your problem. If it doesn't, then try adding the User-Agent one.

ch1ck3n (1627)

if you render the response, it looks like this:

ch1ck3n (1627)

@ch1ck3n Error 1020 Access Denied. This indicates that you've violated a firewall rule and your request is blocked.

ch1ck3n (1627)

@ch1ck3n my gues is you can only access it from the client?

ch1ck3n (1627)

@ch1ck3n That's weird, i can access it from python

DREWNOLT (27)

@ch1ck3n I'm trying to make an api to simplify the first api, but I get a cloudflare error 1020.

RayhanADev (1949)

@DREWNOLT if you're using NodeJS, then check out my package for NodeJS :)