How to fetch replit websites without getting Cloudflare Errors?
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?
@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 ;)
Have you tried adding headers like User-Agent, Host, etc to pretend that the request you're making is coming from a browser?
@RicksNext no, how do I do that?
@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 Error 1020 Access Denied. This indicates that you've violated a firewall rule and your request is blocked.
@ch1ck3n my gues is you can only access it from the client?
@ch1ck3n That's weird, i can access it from python
@ch1ck3n I'm trying to make an api to simplify the first api, but I get a cloudflare error 1020.
@DREWNOLT why cant you use https://replit.com/talk/share/REPLAPI-Module-pogchamp/130491
lol
@ch1ck3n cuz im using nodejs
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 theX-Requested-With
header (any value) andReferrer
header (https://replit.com/). That will fix all your problems.@RayhanADev make sure that your
User-Agent
doesn't look suspicious either, set it to something likeMozilla/5.0
(credits to @firefish).Example: https://repl.it/@programmeruser/graphql
@programmeruser yea true. I never had that problem but it's good to cross all your x's anyways :)