Open manovasanth1227 opened 3 years ago
@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
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
Same thing happened to me
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) });
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",
Im getting error in browser as : POST https://cdn-api.co-vin.in/api/v2/auth/public/generateOTP net::ERR_ABORTED 400