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

unable to create beneficiary #446

Closed aviroop89 closed 3 years ago

aviroop89 commented 3 years ago

Was trying to develop an app using the API set but unable to create beneficiary. What I am doing wrong? Error received - Unauthorized Access

big89 commented 3 years ago

@aviroop89 Make sure you have passed Authorization Bearer token in request header which you will get in response of confirm OTP api.

curl -X POST "https://cdndemo-api.co-vin.in/api/v2/registration/beneficiary/new" -H "accept: application/json" -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d "{\"name\":\"Apparao\",\"birth_year\":\"1980\",\"gender_id\":1,\"photo_id_type\":1,\"photo_id_number\":\"9999\",\"comorbidity_ind\":\"Y\",\"consent_version\":\"1\"}"

Thanks, Logicmaker

aviroop89 commented 3 years ago

At the time of implementing confirmOTP API, getting an error - "Beneficiary not registered" well before getting the Authorization Bearer token. Secondly, what's the Base URL as it is different from the one given in CoWIN site?

big89 commented 3 years ago

Not sure, but there seems some misbehavior with API, that if no Beneficiary added, then confirm OTP sometimes gives such error. Not sure if there is any such validation applied.

We are talking about Co-WIN Protected APIs with Sandbox url: https://cdndemo-api.co-vin.in/api

Thanks, Logicmaker

aviroop89 commented 3 years ago

Thanks for your response...Are you able to generate OTP with the SandBox url? Getting an error 403 (Forbidden)

big89 commented 3 years ago

Yes, just tested below PHP code and its generating OTP using Protected APIs with given Sandbox API Key -

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://cdndemo-api.co-vin.in/api/v2/auth/generateOTP'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, '{"mobile":"9876543210"}');

$headers = array(); $headers[] = 'Accept: application/json'; $headers[] = 'X-Api-Key: 3sjOr2rmM52GzhpMHjDEE1kpQeRxwFDr4YcBEimi'; $headers[] = 'Content-Type: application/json'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch);

echo $result;

Thanks, Logicmaker

aviroop89 commented 3 years ago

Thanks...registered

aviroop89 commented 3 years ago

How are you generating the center list