Open safiyat opened 3 years ago
Hey, what request headers did you add for the validateMobileOtp API? I am getting a "Endpoint request timed out" after I call that API
Here is the code for validateMobileOtp -
function validateOtp() {
var requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
otp: sha256(document.getElementById("otp").value),
txnId: localStorage.getItem("txnId"),
}),
redirect: "follow",
};
fetch(
"https://cdn-api.co-vin.in/api/v2/auth/validateMobileOtp",
requestOptions
)
.then((response) => response.text())
.then((result) => localStorage.setItem("token", JSON.parse(result).token))
.catch((error) => console.log("error", error));
}
Here this the code for generateMobileOTP -
function generateOtp {
var requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
mobile: "888******",
secret:
"U2FsdGVkX1+z/4Nr9nta+2DrVJSv7KS6VoQUSQ1ZXYDx/CJUkWxFYG6P3iM/VW+6jLQ9RDQVzp/RcZ8kbT41xw==",
}),
redirect: "follow",
};
fetch("https://cdn-api.co-vin.in/api/v2/auth/generateMobileOTP", requestOptions)
.then((response) => response.text())
.then((data) => localStorage.setItem("txnId", data.txnId))
.catch((error) => console.log("error", error));
}
Could you help me with this? Thanks
@AdityaPimpalkar
I have a standard set of headers that I use for all the requests. I add the auth token to it once I have it.
The standard set of headers that I use:
{
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0",
"Accept": "application/json",
"Accept-Language": "en-US",
"Referer": "https://apisetu.gov.in/public/api/cowin",
"Origin": "https://apisetu.gov.in",
"DNT": "1",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"TE": "Trailers"
}
When sending a request to generate OTP, this is the body:
{
'mobile': mobile,
'secret': token
}
When validating the same to get the bearer token,
{
'otp': hashed_otp,
'txnId': txn_id
}
From the excerpts you have shared, my suggestion is to add a user agent in the headers. And make sure it is some recognized browser. Use mine, if you don't want to look any further.
For a little more details: https://github.com/cowinapi/developer.cowin/issues/344#issuecomment-851023292
Public API from Cowin gives only cached data, so may not be very accurate. Once after login you get exact availability details. I have used Public Api and developed a site for statistical analysis. http://dreamninja.shop/cowin/ I find it very difficult to use Private API's due to OTP validation and also restrictions in number of calls. Still I have developed a beta app similar to Cowin bot for Chrome which I will share in a week.
@dileepps you may have misread my post. I am using private APIs for getting the data.
hey @safiyat the issue is with the implementation of Authorization Bearertoken : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.**** use authorization as header and value as Bearer token Authorization : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.**** Hope This will work ..>!
hey @safiyat the issue is with the implementation of Authorization Bearertoken : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.**** use authorization as header and value as Bearer token Authorization : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.**** Hope This will work ..>!
@badinenisaivardhan I have used it. Yes. That is why I was getting 200 in some of the protected API hits. I think the issue lies somewhere else.
Hi!
So I have written a little script to query the private APIs of COWIN, periodically logging in using the OTP, and renewing the bearer token.
I use the same bearer token for upto ten minutes (a little less than the 15 minutes expiry), with my requests not crossing 75 per 5 minutes.
The issue I am facing is, even if I have just renewed the token, a third of my queries receive a 401 'Unauthenticated access!' error. What's weirder is that these errors are sporadic, and intermittent. One request receives 200, then the next 401, then the one after that receives 200 again.
Some summaries from the queries:
Any ideas why this could be the case?
I have attached the complete logs below.
cowin.log