Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate OTP error #388

Open
manovasanth1227 opened this issue Jun 3, 2021 · 4 comments
Open

Generate OTP error #388

manovasanth1227 opened this issue Jun 3, 2021 · 4 comments

Comments

@manovasanth1227
Copy link

const OTPGENERATEURL =
"https://cdn-api.co-vin.in/api/v2/auth/public/generateOTP";
const data = {
mobile: **********,
secret:
"U2FsdGVkX1/JL3gfdhdxA7QIYB9xxdXiQd1Mz4frcbUdcoA+q44cPIOD+EZ/mQTKKRQ5jWl6KDmqgDbdgfTadA==",
};
let res = await fetch(OTPGENERATEURL, {
mode: "no-cors",
method: "post",

  headers: {
    "User-Agent":
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",
    accept: "application / json",
    "Content-Type": "application/json",
    "x-api-key": "3sjOr2rmM52GzhpMHjDEE1kpQeRxwFDr4YcBEimi",
  },
  body: JSON.stringify(data),
});

Im getting error in browser as : POST https://cdn-api.co-vin.in/api/v2/auth/public/generateOTP net::ERR_ABORTED 400

@big89
Copy link

big89 commented Jun 6, 2021

@manovasanth1227 If you are trying to get OTP using Public APIs, then your request should be like this -

curl -X POST "https://cdn-api.co-vin.in/api/v2/auth/public/generateOTP" -H "accept: application/json" -H "Content-Type: application/json" -d "{"mobile":"9876543210"}"

Thanks,
Logicmaker

@manovasanth1227
Copy link
Author

const res = await fetch(RECIEVEOTPURL, {
method: "POST",
mode: "no-cors",
headers: {
"Content-Type": "application/json",
accept: "application/json",
},
body: JSON.stringify({ mobile: phone }),
});
console.log(res);

now i replaced what you said but I'm getting same error
Failed to load resource 400 aborted error

@opticSquid
Copy link

Same thing happened to me

@badinenisaivardhan
Copy link

Hey @manovasanth1227 Here is the Working Code For Public And Protected API Generation Using Request In Nodejs. Hope This Help You

//Public API OTP GENERATION

var request = require('request');
var options = {
'method': 'POST',
'url': 'https://cdn-api.co-vin.in/api/v2/auth/public/generateOTP',
'headers': {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Accept': 'application/json, text/plain, /',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"mobile": "PhoneNumber"
})

};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});

//Private Protected API OTP GENERATION
var mobilenumber = req.body.mobilenumber
var options = {
'method': 'POST',
'url': 'https://cdn-api.co-vin.in/api/v2/auth/generateMobileOTP',
'headers': {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Accept': 'application/json, text/plain, /',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"mobile": "PhoneNumber",
"secret": "RandomSecretHash" //Can Be Obtained From Website XHR JSON-Body Call
})

};
request(options,mobilenumber, function (error, response) {
if (error) throw new Error(error);
console.log(response.body)
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants