403 Response code - Request Blocked when using Cowin setu APIs

6

I was just trying to make covid vaccine alert using Cowin Setu API (India) in nodejs. But I am facing some strange thing, whenever I hit get request I got 403 response code from cloudfront says 'Request Blocked' but the same is working from postman as well as from browser. Please help me in this

Getting this error:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: Q1RZ94qgFp6AjUUKE4e9urMB85VejcqMbaJO6Y8Xq5Qp4kNjDBre9A==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

Here's my nodejs code:

var express = require("express");
var app = express();
var bodyParser = require("body-parser");
const axios = require("axios");
const { Telegram } = require("telegraf");
const fetch = require("node-fetch");
var cors = require('cors');
var request=require('request');


const tg = new Telegram(process.env.BOT_TOKEN);
const bot = new Telegram(process.env.BOT_TOKEN, {
polling: true
});

//bot.start((ctx) => ctx.reply('Welcom to Covid Vaccine Finder'))

/*bot.hears("about", ctx => {
ctx.reply("Hey, I am CoviBot!");
});
bot.launch();*/

app.use(bodyParser.json());

app.use(cors());



app.use(
bodyParser.urlencoded({
extended: true
})
);

app.get("/", function(req, res) {
res.send("Welcom to Covid Vaccine Finder");
});

app.get("/test", function(req, res, next) {
var d = new Date();
var options = {
year: "numeric",
month: "2-digit",
day: "2-digit"
};

var date = String(d.toLocaleDateString("en", options));
date = date.replace(/\//g, "-");
console.log(date);

const URL =
"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPinpincode=110088&date=13-05-2021";

var options = { 
url: URL,
method: 'GET',
headers: {
  'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'en-GB,en;q=0.8,en-US;q=0.6,hu;q=0.4',
    'Cache-Control': 'max-age=0',
    Connection: 'keep-alive',
    Host: 'cdn-api.co-vin.in',
    'User-Agent': 'request',


 }
 };
 request(options,function(err,res,body){
  let json = body;
 console.log(json);
 });


const txt = "Finding vaccine centres for you....";
//tg.sendMessage(process.env.GROUP_ID, txt);
res.send(txt);


});



 // Finally, start our server
 app.listen(process.env.PORT, function() {
 console.log("Covid app listening on port 3000!");
 });

I hope this problem will solve

Thanks

Share
Improve this question
14
  • No it's not, because it is working from postman or through curl – shivam sharma May 12 at 6:38
  • Yes, problem is coming only when I hit request from code – shivam sharma May 12 at 6:52
  • Yes, what should I write in host then? – shivam sharma May 12 at 7:00
  • I am using 3rd party AP, and I think it is hosted on cloudfront – shivam sharma May 12 at 7:01
  • 1
    @shivamsharma, am facing similar issue. Works fine on local devevelopment, but when I tried to deploy to production environment, the API returns a 403. My suspicion is that in production environments, the reverse proxy server (Apache/NginX) might be adding/manipulating some Http headers which the Co-Win API doesn't support. Planning to try deploying somewhere as a raw Node server Https server. Will update here if that works. – cyberabis May 13 at 18:20

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

React Native - Image Cache