cowinapi / developer.cowin

This group is created to facilitate technical and integration discussions related to cowin platform. API related contents can be obtained at API setu portal https://apisetu.gov.in/public/marketplace/api/cowin
115 stars 30 forks source link

Generate OTP error #388

Open manovasanth1227 opened 3 years ago

manovasanth1227 commented 3 years ago

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 commented 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

manovasanth1227 commented 3 years ago

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 commented 3 years ago

Same thing happened to me

badinenisaivardhan commented 3 years ago

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) });